我正在尝试按this example通过https下载压缩文件,解压缩csv文件(14GB),然后将数据加载到数据帧中。我创建了一个小例子(< 1MB)。
library(data.table)
temp <- tempfile()
download.file("https://www.dropbox.com/s/h130oe03krthcl0/example.csv.zip",
temp, method="curl")
data <- fread(unz(temp, "example.csv"))
unlink(temp)
我的错误是否明显?
答案 0 :(得分:1)
这对我来说很好(download.file
也可以,但是我在3.2.2 OS X上这样做了更多&#34;便携式&#34;鉴于自download.file
以来的更新3.1.2):
library(httr)
response <- GET("https://www.dropbox.com/s/h130oe03krthcl0/example.csv.zip?dl=1",
write_disk("example.csv.zip"),
progress())
fil <- unzip("example.csv.zip")
read.csv(fil[1], stringsAsFactors=FALSE)
## v1 v2 v3
## 1 1 2 3
## 2 1 2 3
## 3 1 2 3
我没有尝试?dl=1
(&amp; I do that that that write,不是因为编辑队列建议)。
老实说,我可能会将下载放在R中,只需在命令行中使用curl
,即可在自动化工作流程中使用@movie = Movie.all
来显示您已指明的文件(并且,我&#39} ;如果处理语言也是python [et al],那么这样做。
答案 1 :(得分:0)
在我的应用程序中,我试图从http下载zip文件,然后创建流以将该文件解压缩到文件夹中。
在进行了一些Google搜索之后,我能够编写以下代码来帮助我完成任务
这是您必须遵循的几个步骤
安装解压缩包
将解压缩器和http导入代码文件
从“解压缩器”导入解压缩器;
从“ http”导入http;
从“解压缩器”导入解压缩器;
从“ http”导入http;
var self = this;
http.get('http://yoururl.com/file.zip',function(res){
res.pipe(unzipper.Extract({ path: ‘C:/cmsdata/’ })).on(‘close’, function() {
//Here you can perform any action after completion of stream unzipping
});
});