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: 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 a list of packages: getting dependencies in order
The package miniCRAN
can help with this. You tell miniCRAN
the list of packages you would ever want to install, it then figures out the dependencies, downloads those packages and creates a repository on your local machine that behaves like CRAN, i.e. it respects install.packages()
etc.
More information:
Available on CRAN
Read the vignette
We are actively developing
miniCRAN
. Track progress and find the latest development version at github miniCRAN repositorySee the project wiki for links to presentations, blog posts and more
To install from the local miniCRAN
repository, you have two options.
Firstly, you can use the URI convention
file:///
. e.g.install.packages("ggplot2", repos="file:///path/to/file/")
Alternatively, you can configure the destination as an HTTP server and make your repository available via a URL. In this case, your local repository will look and feel exactly like a CRAN mirror, other than it only contains your desired packages.
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")
Related Topics
Tools For Making Latex Tables in R
Unlist Data Frame Column Preserving Information from Other Column
Why Is Rbindlist "Better" Than Rbind
How to Put Labels Over Geom_Bar For Each Bar in R With Ggplot2
Convert Unix Epoch to Date Object
How to Make Consistent-Width Plots in Ggplot (With Legends)
How to Read a CSV File in R With Different Number of Columns
Import Text File as Single Character String
Create New Dummy Variable Columns from Categorical Variable
Method to Extract Stat_Smooth Line Fit
How to Export Multiple Data.Frame to Multiple Excel Worksheets
Scatterplot With Marginal Histograms in Ggplot2
Efficient Way to Rbind Data.Frames With Different Columns
Yaml Current Date in Rmarkdown
Quit and Restart a Clean R Session from Within R