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

Viewed 180

I'm trying to access web server using curl package functions. 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. My IT admin added some exe files from Rstudio and R language folder as exceptions on firewall, so R studio can now install packages. But some other stuff, like curl still doesn't work. Is there any solution, to make R functions work behind Windows firewall?

1 Answers

I've had this issue many times with R. If you are using Windows there is more than one method available to access the internet. You will be familiar with Curl, which is used by many libraries under the hood, e.g. RCurl and httr.

However the method which R uses by default, for operatons like install.packages(), url(), and file() operations is actually based on WinINet. Without getting into the details, WinInet is the same library that Internet Explorer uses to access the 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.

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.

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

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

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

We retrieve the JSON example from https://jsonplaceholder.typicode.com/

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

This method on Windows will use 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.

Related