Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 下载自定义文件时file.download中出错_R_Download - Fatal编程技术网

R 下载自定义文件时file.download中出错

R 下载自定义文件时file.download中出错,r,download,R,Download,我正在尝试从以下url下载zip文件: url1 <- http://www.clinicaltrials.gov/ct2/results?cond=%22acne%22&studyxml=true 有什么想法吗 编辑:好的,在看到下面agstudy的回复后,我发现文件确实被下载了(它似乎也是正确的文件大小)。现在的问题是,当我试图解压文件时,文件已损坏 Maciej,我同意使用扩展名为.zip的链接会更好,但是,从这个网站上无法获得 您没有指向该文件的直接链接。R尝试下载网页而

我正在尝试从以下url下载zip文件:

url1 <- http://www.clinicaltrials.gov/ct2/results?cond=%22acne%22&studyxml=true
有什么想法吗

编辑:好的,在看到下面agstudy的回复后,我发现文件确实被下载了(它似乎也是正确的文件大小)。现在的问题是,当我试图解压文件时,文件已损坏


Maciej,我同意使用扩展名为.zip的链接会更好,但是,从这个网站上无法获得

您没有指向该文件的直接链接。R尝试下载网页而不是文件。使用以“.zip”结尾的链接


使用
XML
RCurl
包从该网页中删除指向数据集的链接可能有用。

好的,我找到了问题所在。由于此url末尾没有明确的“.zip”,因此download.file函数不知道如何使用二进制下载。此代码修复了以下问题:

url1 <- http://www.clinicaltrials.gov/ct2/results?cond=%22acne%22&studyxml=true
tempZip <- tempfile()
download.file(url1, tempZip, mode="wb")
url1
Warning message:
In download.file(url1, tempZip) :
  downloaded length 817445 != reported length 200
url1 <- http://www.clinicaltrials.gov/ct2/results?cond=%22acne%22&studyxml=true
tempZip <- tempfile()
download.file(url1, tempZip, mode="wb")