简体   繁体   English

使用R读取压缩文件夹中的csv文件而不解压缩

[英]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 我有一个名为master.zip的压缩文件,其中包含2个CSV文件: file1.csvfile2.csv

I want to read file1.csv only, something like: read_csv('master/file1.csv') , but without having to unzip master.zip . 我只想读取file1.csv ,类似于: read_csv('master/file1.csv') ,但不必解压缩master.zip How can I achieve this with R? 如何使用R做到这一点?

You just need to use the native function unz() . 您只需要使用本机函数unz() Let's assume that master.zip is in your working directory, 假设master.zip在您的工作目录中,

# 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 = ",") 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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