Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download.file fails in RStudio

Tags:

r

rstudio

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.

like image 642
Dean MacGregor Avatar asked Mar 28 '14 19:03

Dean MacGregor


2 Answers

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.

like image 154
sssheridan Avatar answered Nov 15 '22 05:11

sssheridan


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

like image 44
Xiaohui Avatar answered Nov 15 '22 06:11

Xiaohui