简体   繁体   中英

why method = 'curl' is not working in download.file in R?

I am working in RI want to download an excel file from web and I am using download.file command:

download.file(url = "http://www.jaredlander.com/data/ExcelExample.xlsx",
          destfile="data/ExcelExample.xlsx",method='curl')

But when I try to run the code it displays an error as:

download.file(url = " http://www.jaredlander.com/data/ExcelExample.xlsx ", + destfile="data/ExcelExample.xlsx",method='curl') Error in download.file(url = " http://www.jaredlander.com/data/ExcelExample.xlsx ", : 'curl' call had nonzero exit status.

The link redirects via an http 301 response to an https address, which method = "curl" seems not to like. The "internal" and "wget" methods don't work either.

I'm using Windows and I seem to get away without specifying a method at all - according to the manual the default is "auto", which presumably chooses the most appropriate method for you. In my case this appears to give the same result as method = "wininet" , though method = "libcurl" works too.

If you're using not Windows, try removing method="curl" and it should work fine. Otherwise, try method = "libcurl" .

You can see I can replicate your error even though I have a valid file path.

download.file(url = "http://www.jaredlander.com/data/ExcelExample.xlsx", 
              path.expand("~/jared.xlsx"), method = "curl")
# Error in download.file(url = "http://www.jaredlander.com/data/ExcelExample.xlsx",  : 
#   'curl' call had nonzero exit status

But I can get it to work by just removing "method" altogether.

download.file(url = "http://www.jaredlander.com/data/ExcelExample.xlsx", 
              path.expand("~/jared.xlsx"))
# trying URL 'https://www.jaredlander.com/data/ExcelExample.xlsx'
# Content type 'application/vnd.openxmlformats' length 2045364 bytes (2.0 MB)
# downloaded 2.0 MB

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM