簡體   English   中英

如何獲取R中的tempfile中包含的文件名的向量?

[英]How to get a vector of the file names contained in a tempfile in R?

我正在嘗試使用R自動下載一堆zip文件。這些文件包含各種各樣的文件,我只需要將其中一個作為data.frame加載即可對其進行后處理。 它具有唯一的名稱,因此我可以使用str_detect()來捕獲它。 但是,使用tempfile() ,我無法使用list.files()獲得其中所有文件的列表。

到目前為止,這是我嘗試過的:

temp <- tempfile()

download.file("https://url/file.zip", destfile = temp) 

files <- list.files(temp) # this is where I only get "character(0)"

# After, I'd like to use something along the lines of:
data <- read.table(unz(temp, str_detect(files, "^file123.txt"), header = TRUE, sep = ";")

unlink(temp)

我知道read.table()命令可能不起作用,但是我認為一旦獲得包含tempfiles列表的向量,我就能弄清楚這一點。

我在Windows 7計算機上,正在使用R 3.6.0。

按照前面所說的,此結構應允許您使用臨時文件結構檢查正確的下載:

temp <- tempfile("test.zip")
download.file("https://url/file.zip", destfile = temp) 
files <- list.files(temp)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM