Why works install.packages() even when no internet connection is available?

Working with RStudio on a server within the company's network that has no connection to the internet (basically all ports are closed) I was installing packages by source so far. Until I realized that install.packages actually works. I was puzzled. How does install.packages achive this?
The documentation says install.packages uses download.file to download the package zip.

For example, not surprisingly, both calls below return error messages like
cannot open connection / HTTP status was '403 Forbidden

readLines("https://cran.r-project.org")
download.file(
  url = "https://cran.r-project.org/src/contrib/data.table_1.13.0.tar.gz", 
  destfile = "D:/data.table_1.13.0.tar.gz"
)

I'd like to know the parameters for the connection so that I can download data for other purposes my self with download.file. I failed to find out myself with debugonce(install.packages).

what happens when you use

available.packages()

available.packages() successfully prints the full list to the console.

does it show any particular repository ?

both available.packages and install.packages seem to use the standard CRAN repository
https://cran.rstudio.com/src/contrib

My interest is in the exact connection parameters these functions are using which I possibly should also give to download.file to succesfully connect outside our company network. How could I trace down this?

So you do have and internet connection but it is severely restricted, I would guess the address is simply white listed by your IT department on a firewall or proxy server and there is no loop hole in the R side of things that you can exploit.

Yes, I assume the same. But, why do I have no access interactively running download.file while intsall.packages apparently gets access? I am calling the same URL (CRAN) from the same process (RStudio). A whitelist should not exclude one but not the other here. The connection details in intsall.packages must carry information to get access, like porxy IP and port and how it is forwarded to download.file. How can we access this information, e.g. make install.packeges verbose or debug it? I would like to simulate interactively what intsall.packeges is doing, for example with download.file.

rather than debugonce install.packages,
do debugonce(download.file).
When I did this I found I can cause the downloading with code like

.External(utils:::C_download, "https://cran.rstudio.com/bin/windows/contrib/4.0/scales_1.1.1.zip", 
          file.path(getwd(),"gotscales.zip"), FALSE, 
          "wb", FALSE, NULL, TRUE)

Thing is though, if your server is locked down by your firms security policies, they may not see kindly to your even attempting to sidestep it ... I could imagine scenarious where this couldput you in danger.
I know this is an R forum and not career advice, but if I was in your shoes I would talk to a sysadmin for the server. before proceeding in this direction.

That looks scary :slight_smile: I'd like to debug install.packages, but don't know how.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.