简体   繁体   English

Rstudio(或rterm)使用哪个进程访问Internet?

[英]Which process is used by Rstudio (or rterm) to access Internet?

I'm trying to access web server using curl package functions.我正在尝试使用 curl package 函数访问 web 服务器。 I'm getting "recv failure: connection was reset" error.我收到“接收失败:连接已重置”错误。 I know, that this is firewall problem, because in other network, it works.我知道,这是防火墙问题,因为在其他网络中,它可以工作。 So I need to know which process is used by Rstudio to access the Internet.所以我需要知道Rstudio是用哪个进程来上网的。 My IT admin added some exe files from Rstudio and R language folder as exceptions on firewall, so R studio can now install packages.我的 IT 管理员在防火墙上添加了一些来自 Rstudio 和 R 语言文件夹的 exe 文件作为例外,因此 R 工作室现在可以安装软件包。 But some other stuff, like curl still doesn't work.但是其他一些东西,比如 curl 仍然不起作用。 Is there any solution, to make R functions work behind Windows firewall?有什么解决方案可以让 R 功能在 Windows 防火墙后面工作?

I've had this issue many times with R. R 多次遇到这个问题。 If you are using Windows there is more than one method available to access the internet.如果您使用的是 Windows,则有不止一种方法可以访问互联网。 You will be familiar with Curl, which is used by many libraries under the hood, eg RCurl and httr.您将熟悉 Curl,许多库在后台使用它,例如 RCurl 和 httr。

However the method which R uses by default, for operatons like install.packages(), url(), and file() operations is actually based on WinINet .然而 R 默认使用的方法,对于 install.packages()、url() 和 file() 等操作,实际上是基于WinINet的。 Without getting into the details, WinInet is the same library that Internet Explorer uses to access the web.无需赘述,WinInet 与 Internet Explorer 用于访问 web 的库相同。

WinINet is more limited in its functionalities than Curl but if you are doing something as basic as downloading a file you shouldn't have an issue. WinINet 的功能比 Curl 更受限制,但如果您正在做一些像下载文件这样基本的事情,那么您应该没有问题。

Below you will see an example of how to take a script written with httr and re-do it so that it can be done using functions like url .下面您将看到一个示例,说明如何使用 httr 编写脚本并重新执行它,以便可以使用url类的函数来完成。

You should also note that on Windows you can change the default of file and url so that they rely on curl rather than WinINet, assuming you have curl installed. You should also note that on Windows you can change the default of file and url so that they rely on curl rather than WinINet, assuming you have curl installed.

Here is some code which downloads files using httr这是一些使用 httr 下载文件的代码

library(httr)
url <- "https://rawgit.com/yoke2/dsxref/master/iris.xlsx"
GET(url, write_disk("iris.xlsx", overwrite=TRUE))

And here is the equivalent with download.file()这是与download.file()的等价物

url = "https://vincentarelbundock.github.io/Rdatasets/csv/datasets/iris.csv"
download.file(url, "iris.csv", quiet=TRUE)

Here is some code to do a curl GET operation using httr这是使用 httr 执行 curl GET 操作的一些代码

We retrieve the JSON example from https://jsonplaceholder.typicode.com/我们从https://jsonplaceholder.typicode.com/检索 JSON 示例

library(httr)
response <- httr::GET('https://jsonplaceholder.typicode.com/todos/1')
content <- httr::content(response)

And here is a way to do it relying on url这是一种依靠url的方法

This method on Windows will use WinINet Windows 上的这种方法将使用 WinINet

library(jsonlite)
u <- url('https://jsonplaceholder.typicode.com/todos/1')
json <- readLines(u, warn = FALSE)
content <- parse_json(json)

You can learn a little bit more about WinINet by using the help command on any of the related functions ( url , file , file.download ), which is a good place to start to get your head around things.您可以通过对任何相关函数( urlfilefile.download )使用help命令来了解更多关于 WinINet 的信息,这是开始了解事物的好地方。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM