在 R 和 RStudio 中读取 URL [英] Reading URL in R and RStudio

查看:133
本文介绍了在 R 和 RStudio 中读取 URL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 RStudio 中输入以下内容时,它工作正常:

When I type the following in RStudio it works fine:

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

但是当我在 R 控制台中输入相同的内容时,出现此错误:

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)'

我已经检查并重新检查了一千次,RStudio 和 R 之间的一切似乎完全相同(相同版本等),那么为什么会出现错误?

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?

推荐答案

RStudio 和 R 控制台之间的代理设置或其他网络设置可能存在差异.例如,internet2"选项(在调用 R 时在命令行上定义)的使用可能不同.setInternet2(NA) 在每个平台上都会显示设置.如果结果不同,这可能是差异的根源.

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 中读取 URL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆