在R中从子文件夹读取zip文件

6

我很苦恼这个问题。我正在尝试运行以下命令:

temp <- tempfile()
download.file("http://seanlahman.com/files/database/baseballdatabank-2017.1.zip", temp, mode="wb")
table1 <- unz(temp, "Salaries.csv")
salaries <- read.csv(table1, sep=",", header=T)

然而,我认为它没有运行是因为我想要的实际文件(薪资)位于一个名为“core”的文件夹中 - 我通过将压缩文件下载到我的计算机上查看了结构。如何在此代码中添加内容以查看核心文件夹并获取薪资数据?如果可能的话,我想直接从URL中进行操作。谢谢!

1个回答

4
您可以明确指定存档文件中的路径:
temp <- tempfile()
download.file("http://seanlahman.com/files/database/baseballdatabank-2017.1.zip", temp, mode="wb")
table1 <- unz(temp, "baseballdatabank-2017.1/core/Salaries.csv")
salaries <- read.csv(table1, sep=",", header=T)

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接