OHDSI Home | Forums | Wiki | Github

Installing study package (dependencies) on a machine without internet connection

I’m aware some institutions don’t allow access to the internet from computers that can access their data in the CDM. This can be a challenge when study packages come with an renv lock file, like for example the PhenotypePhebruary study package.

One way to make your life easier is to install the study package and its dependency on your laptop, and move the already installed package (and dependencies) over to the secure environment. That way you don’t need to access the internet anymore to run it. This does require that you use the same version of R, and the same operating system in both environments (all 64-bit Windows versions are considered to be the same OS).

On your laptop

On your laptop, download and install the study package, run renv::restore() as instructed, and build and install the study package. Then run this script:

# This script assumes you have run renv::restore() successfully, and that the working directory 
# is the root of the project.

# Folder where the zip file containing the binaries of all dependencies will be stored:
folder <- "c:/temp"

fileName <- file.path(folder, sprintf(
  sub("\\.", "_", R.version$minor),
path <- renv::paths$library()
packageFolders <- list.dirs(path, recursive = FALSE)
tempFolder <- tempfile()
for (packageFolder in packageFolders) {
  message(sprintf("Copying %s", basename(packageFolder)))
  file.copy(from = packageFolder, tempFolder, recursive = TRUE, overwrite = TRUE)
oldFolder <- setwd(tempFolder)
  zipfile = fileName, 
  files = list.dirs(tempFolder, recursive = FALSE, full.names = FALSE), 
  recurse = TRUE, 
  include_directories = TRUE
unlink(tempFolder, recursive = TRUE)

(Explanation: This copies all the binaries from the renv package library to the zip file. For some reason file.copy() magically resolves symbolic links. The first part is just me being picky about having an informative name for the zip file :wink: )

On your secure machine

Move the zip file (as well as the study project folder itself) to the secure machine. There, open the study project, and instead of running renv, use this script:

# This script assumes you have moved the zip file to the machine without internet connection,
# and that you currently have the study project open. You may need to install zip and renv.

# The path to the zip file:
zipFile <- "c:/temp/lib_PhenotypePhebruary2023-master_R4_1_0_x86_64-w64-mingw32.zip"

path <- renv::paths$library()
zip::unzip(zipFile, exdir = path)

# You can now activate renv:

(Explanation: This unzips the zip file into the renv project library, so all binaries will be ready for use.)

1 Like

Works like a charm, thank you!