I have an url, and I want to download the file via R
, I notice that download.file
would be helpful, but my problem seems different:
url <- "http://journal.gucas.ac.cn/CN/article/downloadArticleFile.do?attachType=PDF&id=11771"
destfile <- "myfile.pdf"
download.file(url, destfile)
It doesn't work! I notice that if my url
is in the form of xxx.pdf
, then the code above is no problem, otherwise the file that is downloaded is corrupt.
Does anyone know how to solve this problem?
file() function in R. Then use the function download. file(url, filename) to download the file. Here, url is a string containing the URL of the file, and filename is the filename of the destination file.
Setting the mode might be required to treat the file as binary data while saving it. If I leave that argument out, I get a blank file, but this way works for me:
url <- "http://journal.gucas.ac.cn/CN/article/downloadArticleFile.do?
attachType=PDF&id=11771"
destfile <- "myfile.pdf"
download.file(url, destfile, mode="wb")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With