WenZ
WenZ

Reputation: 53

Error in RStudio with read.table(url...)

I tried to run the code below in RStudio, it always returns the error message of connection failure. It works in RGui. Any idea why this is and how to fix it? Is it problem with my Rstudio (I'm running Windows 8)?

survey <- read.table(url("ftp://ftp.ics.uci.edu/pub/machine-learning-databases/adult/adult.data"), 
                header=FALSE, sep=",", quote="", stringsAsFactors=FALSE)

Error in file(file, "rt") : cannot open the connection
In addition: Warning message:
In file(file, "rt") :
  InternetOpenUrl failed: 'The FTP session was terminated
b'

Alternative code I have tried:

survey <- read.table(url('ftp://ftp.ics.uci.edu/pub/machine-learning-databases/adult/adult.data'), 
                header=FALSE, sep=",", quote="", stringsAsFactors=FALSE)

survey <- read.table('ftp://ftp.ics.uci.edu/pub/machine-learning-databases/adult/adult.data', 
                header=FALSE, sep=",", quote="", stringsAsFactors=FALSE)

Thanks!

Upvotes: 2

Views: 2309

Answers (1)

sefleuria
sefleuria

Reputation: 56

RStudio and RGUI may be using different defaults for setInternet2(), so try running setInternet2(use=FALSE) at the beginning of your session.

Here is an explanation from RStudio (2013):

Also we call setInternet2(use=TRUE) on startup which takes proxy settings from Internet Explorer to make proxies work in the majority of cases. We also have an open bug to allow users to turn this off on startup, but for now you'll have to call setInternet2(use=FALSE) manually for each session. For more information on the command, call the following from the console: ?setInternet2()

https://support.rstudio.com/hc/communities/public/questions/200657716-Rstudio-with-aproxy

For Windows, you may have the option to turn this off within RStudio, as someone with Windows mentioned the solution below (2014):

One solution was to go to Tools > Global Options > Packages, and unselect "Use Internet Explorer library/proxy for HTTP".

https://support.rstudio.com/hc/communities/public/questions/201327633-Bug-report-RStudio-causes-download-file-to-fail-with-FTP-downloads

Upvotes: 3

Related Questions