![](/img/trans.png)
[英]R & quosures - How to get names of symbols contained in a vector passed as function argument?
[英]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()
命令可能不起作用,但是我认为一旦获得包含temp
内files
列表的向量,我就能弄清楚这一点。
我在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.