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

Read a zip file in R from a subfolder

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

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' 的文件夹中 - 我通过将压缩文件下载到我的计算机来查看结构。如何向此代码添加一些内容以查看核心文件夹并获取 Salaries 数据?如果可能,我想直接从 URL 执行此操作。谢谢!

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

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)