@EZGraphs在推特上写道:“很多在线data.frame都是压缩的。有没有办法下载、解压缩档案,然后使用R将数据加载到csvs?#Rstats”
我今天也在尝试这样做,但最终只是手动下载了zip文件。
我试过这样的方法:
fileName <- "http://www.newcl.org/data/zipfiles/a1.zip"
con1 <- unz(fileName, filename="a1.dat", open = "r")
但我觉得我似乎还有很长的路要走。有什么想法吗?
发布于 2010-06-16 23:29:59
为了记录,我试着把Dirk的答案翻译成代码:-P
temp <- tempfile()
download.file("http://www.newcl.org/data/zipfiles/a1.zip",temp)
con <- unz(temp, "a1.dat")
data <- matrix(scan(con),ncol=4,byrow=TRUE)
unlink(temp)
发布于 2014-12-09 06:57:45
我使用了在http://cran.r-project.org/web/packages/downloader/index.html找到的CRAN包"downloader“。容易多了。
download(url, dest="dataset.zip", mode="wb")
unzip ("dataset.zip", exdir = "./")
发布于 2016-06-15 08:19:47
对于Mac (我假设是Linux)...
如果压缩包只包含一个文件,您可以使用bash命令funzip
,与data.table
包中的fread
结合使用:
library(data.table)
dt <- fread("curl http://www.newcl.org/data/zipfiles/a1.zip | funzip")
在归档包含多个文件的情况下,您可以使用tar
将特定文件提取到标准输出:
dt <- fread("curl http://www.newcl.org/data/zipfiles/a1.zip | tar -xf- --to-stdout *a1.dat")
https://stackoverflow.com/questions/3053833
复制相似问题