简体   繁体   中英

read a csv file in a zipped folder with R without unzipping

I have a zipped file named master.zip which contains 2 CSV files inside it: file1.csv and file2.csv

I want to read file1.csv only, something like: read_csv('master/file1.csv') , but without having to unzip master.zip . How can I achieve this with R?

You just need to use the native function unz() . Let's assume that master.zip is in your working directory,

# just a list of files inside master.zip
master <- as.character(unzip("master.zip", list = TRUE)$Name)
# load the first file "file1.csv"
data <- read.csv(unz("master.zip", "file1.csv"), header = TRUE,
                 sep = ",") 

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