TL;DR
Assume a folder which contains the source ( *.tar.gz
) archives of R libraries with all the needed dependencies. How do I determine the order in which I should install these packages, knowing that dpendencies must be installed before their respective dependent library?
Use Case
I have a remote machine with no access to the internet. Thus, I have to download libraries manually on my office machine, transfer them to the remote machine and install them there locally.
Current Solution
Following the advice from Install packages in R without internet connection with all dependencies I get a list of all recursive dependencies of the the package I want to install, download them (as source) to a network drive and can eventually install them from there.
getDependencies <- function(packs){
dependencyNames <- unlist(
tools::package_dependencies(packages = packs, db = available.packages(),
which = c("Depends", "Imports"),
recursive = TRUE))
packageNames <- union(packs, dependencyNames)
packageNames
}
# Calculate dependencies
packages <- getDependencies(c("tidyverse", "data.table"))
download.packages(pkgs = packages, destdir = getwd(), type = "source")
Problem
With all the *.tar.gz
files being properly downloaded to the network drive, I could theoretically loop through all files in this transfer directory and install them one by one. The problem, of course, lies in the dependencies, because package A
may rely on package B
, hence, package B
should be installed prior to package B
.
I could save packages
in a csv
(actually that's what the original post does), and read in this file in reverse order (assuming that package_dependencies
lists dependencies after the dependent packages) and install the packages in this order.
I was now wondering, though, if I could achieve the same thing without the workaround of saving the list simply by using the downloaded packages themselves? Bea in mind that on the remote machine, I have no connection to the internet, so any solution must work purely with the information at hand. That is the *.tar.gz
files and any other information obtainable from plain R
.