我看到很多用RCurl下载二进制文件的例子都是这样的:
library("RCurl")
curl = getCurlHandle()
bfile=getBinaryURL (
"http://www.example.com/bfile.zip",
curl= curl,
progressfunction = function(down, up) {print(down)}, noprogress = FALSE
)
writeBin(bfile, "bfile.zip")
rm(curl, bfile)
Run Code Online (Sandbox Code Playgroud)
如果下载非常大,我想最好将它同时写入存储介质,而不是在内存中获取所有内容.
在RCurl文档中,有一些示例可以通过块获取文件并在下载时对其进行操作,但它们似乎都是指文本块.
你能给出一个有效的例子吗?
用户建议使用R native download file和mode = 'wb'二进制文件选项.
在许多情况下,本机函数是一个可行的替代方案,但是有许多用例不适合这种本机函数(https,cookie,表单等),这就是RCurl存在的原因.
想要从 FTP 服务器下载 csv 文件到 R(最好将该文件作为 R 中的数据帧)。
尝试将 csv 文件从 FTP 服务器下载到 R(在我的 Mac 中是本地的)时收到错误消息。
url = "ftp://ftppath/www_logs/testfolder/"
download.file(URL,"test.csv", credentials = "xxx:yyyy")
Run Code Online (Sandbox Code Playgroud)
最后一个查询导致:
Error in download.file(URL, "test.csv", credentials = "xxxyyy", :
unused arguments (credentials = "xxx:yyyy")
Run Code Online (Sandbox Code Playgroud)