0

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?

Esben Eickhardt
  • 3,183
  • 2
  • 35
  • 56
  • are all these packages up to date ? (I think I can infer that they are from your question but to be sure) – moodymudskipper Aug 09 '18 at 14:14
  • The linked post suggests using `contriburl="file:///path/to/packages/"`, not `contriburl="/path/to/packages/"`. Have you tried that? – duckmayr Aug 09 '18 at 14:21
  • Argh, sorry, I will just edit the post, as I already did use file:. Yeah, the packages are up to date, as they are downloaded from CRAN. – Esben Eickhardt Aug 09 '18 at 15:22

1 Answers1

2

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")
MrFlick
  • 195,160
  • 17
  • 277
  • 295
  • Does the installation the just work as in my post, where I just refer to the contriburl? – Esben Eickhardt Aug 10 '18 at 06:57
  • @EsbenEickhardt I've updated to show that you would set the `repos=` parameter when installing after you've created the miniCRAN repo. More details at the [miniCRAN introduction vignette](https://cran.r-project.org/web/packages/miniCRAN/vignettes/miniCRAN-introduction.html) – MrFlick Aug 10 '18 at 15:26