Reading URL in R and RStudio

2019-05-02 10:01发布

问题:

When I type the following in RStudio it works fine:

nyt1 <- read.csv(url("http://stat.columbia.edu/~rachel/datasets/nyt1.csv"))

But when I type the same thing in the R console, I get this error:

Error in open.connection(file, "rt") : cannot open the connection
In addition: Warning message:
In open.connection(file, "rt") : cannot open: HTTP status was '0 (nil)'

I have checked and rechecked a thousand times and everything seems to be exactly the same between RStudio and R (same versions, etc), so why the error?

回答1:

There can be differences in proxy settings or other network settings between RStudio and the R Console. As one example, the use of the "internet2" option (defined on the command line when R is invoked) could differ. setInternet2(NA) on each platform will show the setting. If the result of that differs, that could be the source of the difference.



标签: r rstudio