8
file<-tempfile(fileext=".csv")
download.file(url="ftp://pubftp.spp.org/Markets/DA/LMP_By_SETTLEMENT_LOC/2014/03/28/DA-LMP-SL-201403280100.csv",destfile=file,mode="wb")

This works in R proper (I'm not sure what to call it). However in RStudio it hangs for several minutes and then I get the following

trying URL 'ftp://pubftp.spp.org/Markets/RTBM/LMP_By_SETTLEMENT_LOC/2014/03/25/11/RTBM-LMP-SL-201403251015.csv'
using Synchronous WinInet calls
Error in download.file(url = "ftp://pubftp.spp.org/Markets/RTBM/LMP_By_SETTLEMENT_LOC/2014/03/25/11/RTBM-LMP-SL-201403251015.csv",  : 
  cannot open URL 'ftp://pubftp.spp.org/Markets/RTBM/LMP_By_SETTLEMENT_LOC/2014/03/25/11/RTBM-LMP-SL-201403251015.csv'
In addition: Warning message:
In download.file(url = "ftp://pubftp.spp.org/Markets/RTBM/LMP_By_SETTLEMENT_LOC/2014/03/25/11/RTBM-LMP-SL-201403251015.csv",  :
  InternetOpenUrl failed: ''

It is a small file so it shouldn't time out but I really don't know what the problem is.

Mathias Müller
  • 21,291
  • 13
  • 56
  • 74
Dean MacGregor
  • 7,861
  • 7
  • 32
  • 61

5 Answers5

5

I found two solutions.

1) Go to Tools > Global Options > Packages, and unselect "Use Internet Explorer library/proxy for HTTP".

2) This worked for another user, but not for me: setInternet2(use=FALSE)

(https://support.rstudio.com/hc/communities/public/questions/200656136-Issue-With-RStudio-and-GEOquery)

Note: when in RGUI I entered setInternet2(use=TRUE), then tried the download, it gave the "using Synchronous WinInet calls" messages and hung; but then Windows Firewall popped up, and when I allowed RGUI through it, the download began.

sssheridan
  • 640
  • 1
  • 6
  • 14
1

I have the same problem when I download a file in RStudio when using

> source("http://www.statmethods.net/RiA/wmc.txt")
Error in file(filename, "r", encoding = encoding) : 
  cannot open the connection
In addition: Warning message:
In file(filename, "r", encoding = encoding) :
  InternetOpenUrl failed: '安全频道支持出错'

Then I try

> options(download.file.method="libcurl", url.method="libcurl")
> source("http://www.statmethods.net/RiA/wmc.txt")
> wmc

It worked

Xiaohui
  • 11
  • 1
  • Please don't add the same answer to multiple questions. Answer the best one and flag the rest as duplicates. See [Is it acceptable to add a duplicate answer to several questions?](//meta.stackexchange.com/q/104227) – Dharman Jan 21 '20 at 14:05
0

I had a similar issue using R's download.file in a for loop in RStudio. It would download the url for the first several links and then I'd get "InternetOpenUrl failed: 'The operation timed out'" for all subsequent downloads. I tried the the suggestion by sssheridan to unselect the Internet Explorer option in R global options which did not work. I also tried setInternet2(use=T) but this is no longer available in R.

What worked for me was to remove the cache by including cacheOK = F as an argument in download.file. I think this is because I had previously hit the links that were timing out.

moki
  • 90
  • 1
  • 13
0

Go to Tools > Global Option > Packages > uncheck "Use secure download method for HTTP".

Stephen Rauch
  • 44,696
  • 30
  • 102
  • 125
Rockey
  • 1
-5

This works!

file<-'http://data.baltimorecity.gov/api/views/dz54-2aru/rows.csv?accessType=DOWNLOAD' download.file(file, destfile="camera1.csv")

ronald
  • 23
  • 1
  • 2
    Welcome to Stack Overflow! Please try to flesh out your answer a bit more. Just posting a code block without any explanation or context is not good. In its current state your answer might not be of any use to people looking for an answer to this question in the future. – Xaver Kapeller May 04 '14 at 02:20