Firstly, I am aware of the other post on the topic, but it does not resolve my problem.
Offline install of R package and dependencies
I need to install a number of packages on an offline Ubuntu machine, but the dependencies keep messing up.
First I download all packages and dependencies using the following code (on an online ubuntu machine):
# Loading library
library(tools)
# Function for downloading packages and dependencies
getPackages <- function(packs){
packages <- unlist(
tools::package_dependencies(packs, available.packages(),
which=c("Depends", "Imports"), recursive=TRUE)
)
packages <- union(packs, packages)
packages
}
# Determining what packages to download
packages <- getPackages(c("tidyverse", "data.table", "RODBC", "RJDBC", "fasttime", "tidyr", "knitr", "randomForest", "RMySQL", "jsonlite"))
# Downloading packages
download.packages(pkgs = packages, destdir = "/path/to/packages/")
# Writing files such that this folder can be used as a repository
write_PACKAGES("/path/to/packages/")
Second I install the packages on an offline machine with the following commands, as found in the linked post.
# Installs local packages
install.packages(c("tidyverse", "data.table", "RODBC", "RJDBC", "fasttime", "tidyr", "knitr", "randomForest", "RMySQL", "jsonlite"), contriburl = "file:///path/to/packages/")
What happens is that the installation works on a few packages and then crashes with the messages.
ERROR: dependency ‘dplyr’ is not available for package ‘tidyr’
* removing ‘/home/h52z/R/x86_64-pc-linux-gnu-library/3.4/tidyr’
ERROR: dependencies ‘dplyr’, ‘tidyr’ are not available for package ‘tidyverse’
* removing ‘/home/h52z/R/x86_64-pc-linux-gnu-library/3.4/tidyverse’
Warning messages:
1: In install.packages(c("tidyverse", "data.table", "RODBC", "RJDBC", :
installation of package ‘dplyr’ had non-zero exit status
2: In install.packages(c("tidyverse", "data.table", "RODBC", "RJDBC", :
installation of package ‘tidyr’ had non-zero exit status
3: In install.packages(c("tidyverse", "data.table", "RODBC", "RJDBC", :
installation of package ‘tidyverse’ had non-zero exit status
It seems that the installer cannot handle the dependencies despite creating a local repository using the tools library. It will be a lot of work, having to find out myself in which order the packages should be installed.
Do you have any suggestions? Do I have to get into tools like miniCRAN, or do I need to downloade the entire CRAN repository as in the example in the other link?
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")