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

时间:2017-05-16 19:40:12

标签: r url unzip

我一直在用我的头发撕开。我正在尝试运行以下内容:

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)

但是,我认为它不起作用,因为我想要的实际文件(工资)位于名为“核心”的文件夹中。 - 我通过将压缩文件下载到我的计算机来查看结构。如何在此代码中添加内容以查看核心文件夹并获取Salaries数据?如果可能,我想直接从URL中执行此操作。谢谢!

1 个答案:

答案 0 :(得分:3)

您可以在存档文件中明确指定路径:

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)