decompression - Automate zip file reading in R -
decompression - Automate zip file reading in R -
i need automate r read csv datafile that's zip file.
for example, type:
read.zip(file = "myfile.zip") and internally, done is:
unzipmyfile.zip temporary folder read file contained on using read.csv if there more 1 file zip file, error thrown.
my problem name of file contained zip file, in orded provide read.csv command. know how it?
update
here's function wrote based on @paul answer:
read.zip <- function(zipfile, row.names=null, dec=".") { # create name dir we'll unzip zipdir <- tempfile() # create dir using name dir.create(zipdir) # unzip file dir unzip(zipfile, exdir=zipdir) # files dir files <- list.files(zipdir) # throw error if there's more 1 if(length(files)>1) stop("more 1 info file within zip") # total name of file file <- paste(zipdir, files[1], sep="/") # read file read.csv(file, row.names, dec) } since i'll working more files within tempdir(), created new dir within it, don't confused files. hope may useful!
you can utilize unzip unzip file. mention not clear question whether knew that. in regard reading file. 1 time extracted file temporary dir (?tempdir), utilize list.files find files dumped temporary directory. in case 1 file, file need. reading using read.csv quite straightforward:
l = list.files(temp_path) read.csv(l[1]) assuming tempdir location stored in temp_path.
r decompression
Comments
Post a Comment