简体   繁体   中英

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

I am trying to automatically download a bunch of zipfiles using R. These files contain a wide variety of files, I only need to load one as a data.frame to post-process it. It has a unique name so I could catch it with str_detect() . However, using tempfile() , I cannot get a list of all files within it using list.files() .

This is what I've tried so far:

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)

I know that the read.table() command probably won't work, but I think I'll be able to figure that out once I get a vector with the list of the files within temp .

I am on a Windows 7 machine and I am using R 3.6.0.

Following what was said before, this structure should allow you to check the correct download with a temporary file structure :

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM