使用R读取压缩文件夹中的csv文件而不解压缩 [英] read a csv file in a zipped folder with R without unzipping
本文介绍了使用R读取压缩文件夹中的csv文件而不解压缩的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个名为master.zip
的压缩文件,其中包含2个CSV文件:file1.csv
和file2.csv
I have a zipped file named master.zip
which contains 2 CSV files inside it: file1.csv
and file2.csv
我只想读file1.csv
,类似:read_csv('master/file1.csv')
,但不必解压缩master.zip
.我如何用R做到这一点?
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?
推荐答案
您只需要使用本机函数unz()
.假设master.zip
在您的工作目录中,
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 = ",")
这篇关于使用R读取压缩文件夹中的csv文件而不解压缩的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文