2

For offline linux machines without Internet, installing R packages with lots of dependencies is a nightmare. I found couple of posts in SE discussing on how to create a local folder, copy desired package zip files and install using 'install.packages'.

However, finding, downloading, and uploading lots of packages to an offline server is a time-consuming effort. So, I am wondering how can I download the entire zip file of all CRAN packages so I can put them in a http web server directory in my local offline machine and act like a real repository. The size probably will be very big around 200 GB, but for corporate environment, I think it should make sense.

I found a guide here discussing how to become an official CRAN mirror, but I am not going to be an official public mirror.

Please advise. Thanks in advance

Espanta
  • 1,080
  • 1
  • 17
  • 27
  • 5
    You can still follow the advice from the CRAN mirror howto and just not make the mirror official but just run it on your internal machine. – Achim Zeileis Aug 20 '16 at 07:40
  • Visit this link, see if problem is resolved. http://stackoverflow.com/questions/10807804/offline-install-of-r-package-and-dependencies – Sowmya S. Manian Aug 20 '16 at 07:51
  • 4
    Do what @AchimZeileis suggests and mirror CRAN. It's ultimately less load on their server(s) and you get the benefit of exploring and finding some hidden gems in the directory structure (like rds files with great metadata). I setup a local/home CRAN mirror earlier this year and it's been great having package installs happen in milliseconds. You can also selectively mirror it (i.e. can exclude Windows or macOS directory structures if you don't have those systems). – hrbrmstr Aug 20 '16 at 09:45
  • Setting up a mirror seems like the smarter way to tackle this problem. CRAN says that you must mirror twice a week.(?) Perhaps your "corporate environment" would not allow you to do so? – shayaa Aug 20 '16 at 18:30
  • thanks guys, I appreciate your assistances. I will do use your advises for sure. – Espanta Aug 20 '16 at 21:48

1 Answers1

2

You can use the function available.packages to find the available packages.

pkgnames <- available.packages()[,1]

If you like web scraping you can practice as follows.

library(rvest)
pkgs <- read_html("https://cran.r-project.org/web/packages/available_packages_by_name.html")
tab <- html_nodes(pkgs, "table") %>% html_table(fill = TRUE)

pkgnames <- tab[[1]][1]$X1
pkgnames <- pkgnames[nchar(pkgnames)>0]

DON'T RUN THESE UNLESS YOU WANT TO INSTALL (OR DOWNLOAD) A LOT OF PACKAGES!!

#sapply(pkgnames, install.packages)
#sapply(pkgnames, install.packages)

You can run this line to show that it works.

sapply(pkgnames[1:2], install.packages)

You can replace the install.packages with download.packages along with the destdir argument to save it to your corporate directory.

shayaa
  • 2,787
  • 13
  • 19
  • Simply using `available.packages()` would also get you the information about all packages available on CRAN. You don't need to parse the HTML pages for that. – Achim Zeileis Aug 20 '16 at 07:37
  • Your solution does not DOWNLOAD packages, rather it install them. I do not have internet access on the server machine. I found your solution useful if you change install.packages to download.packages() – Espanta Sep 05 '16 at 05:21
  • sapply(pkgnames, download.packages, destdir="d:/desiredFolder") This code will download all the source zip files into desiredFolder. Then, I can copy to my Server and set the repository to this folder so I install all of them locally. – Espanta Sep 05 '16 at 05:21
  • Also, you need to add parenthesis in your first line pkgnames <- available.packages()[,1] – Espanta Sep 05 '16 at 05:22
  • Yes, wasn't sure what your work server enabled, so I wrote both. I edited the parenthesis typo. – shayaa Sep 05 '16 at 06:40