Offline Installation of R Packages

Offline install of R package and dependencies

The correct answer was given by Joshua Ulrich in the comment on the question:

The key is prefixing the argument to either repos or contriburl with file://. So in Unixy systems one could do:

install.packages("ggplot2", contriburl="file:///path/to/packages/")

This assumes that all required source packages, as well as a PACKAGES index file is available in /path/to/packages. If no PACKAGES file is present, this should be generated first using:

library(tools)
write_PACKAGES("/path/to/packages/")

which will generate an index of all source packages found in this directory. Note that in the example, there are 3 slashes behind the file: prefix. The third slash indicates a path relative to the root of the file system.

The difference between the repos and contriburl argument is that repos will append another /src/contrib to the path specified, as this is usually where source packages are located on an official CRAN repository mirror.

R script: Installing packages from offline miniCRAN, still tries to access internet

My bad. The script should look like this:

install.packages('yaImpute', 
repos = paste0("file:///", "C:/Temp/miniCRAN/"),
type = "source")

R: How do I install packages and dependencies offline

I would suggest miniCRAN and specifically the pkgDep function to take care of all the dependency stuff. For example

library(miniCRAN)

pkgs <- c("tidyverse", "data.table", "RODBC", "RJDBC", "fasttime", "tidyr",
"knitr", "randomForest", "RMySQL", "jsonlite")
pkgList <- pkgDep(pkgs, type = "source", suggests = FALSE)
makeRepo(pkgList, path="/path/to/packages/", type = c("source"))

And then you would install from the repo with

install.packages(pkgs, repos="file://path/to/packages/", type="source")

offline installation of packages in R - empty index file generated

I was able to install the package that I wanted (package name = dplyr), using the hints in the comments above. I needed to change two things

  1. I downloaded windows binaries instead of source files, using type = "win.binary" parameter in the download.packages command.

  2. The path in contriburl = "file:///" needed to be changed to contriburl = "file:///<ABSOLUTE_PATH_TO_FOLDER_WITH_WIN_BINARIES>"

With these changes, the package installation went successfully.

Hope it helps others.

SN248



Related Topics



Leave a reply



Submit