Skip to content

Commit

Permalink
Fix local library locations and use withModuleEnv for module instanti…
Browse files Browse the repository at this point in the history
…ation
  • Loading branch information
anthonysena committed Sep 13, 2023
1 parent df1bbfb commit 0f0c5b1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 25 deletions.
13 changes: 7 additions & 6 deletions R/ModuleEnv.R
Original file line number Diff line number Diff line change
Expand Up @@ -85,12 +85,13 @@ withModuleRenv <- function(code,
if (useLocalStrategusLibrary) {
script <- c(.getLocalLibraryScipt("Strategus"), script)
# Adding Strategus dependencies to the script
c(.getLocalLibraryScipt("R6"), script)
c(.getLocalLibraryScipt("CohortGenerator"), script)
c(.getLocalLibraryScipt("DatabaseConnector"), script)
c(.getLocalLibraryScipt("keyring"), script)
c(.getLocalLibraryScipt("openssl"), script)
c(.getLocalLibraryScipt("dplyr"), script)
script <- c(.getLocalLibraryScipt("ParallelLogger"), script)
script <- c(.getLocalLibraryScipt("CohortGenerator"), script)
script <- c(.getLocalLibraryScipt("DatabaseConnector"), script)
script <- c(.getLocalLibraryScipt("keyring"), script)
script <- c(.getLocalLibraryScipt("openssl"), script)
script <- c(.getLocalLibraryScipt("dplyr"), script)
script <- c(.getLocalLibraryScipt("R6"), script)
}

# Write file and execute script inside an renv
Expand Down
31 changes: 12 additions & 19 deletions R/ModuleInstantiation.R
Original file line number Diff line number Diff line change
Expand Up @@ -191,25 +191,18 @@ instantiateModule <- function(module, version, remoteRepo, remoteUsername, modul
stop(message)
}

script <- paste(
c(
"renv::install(c('ParallelLogger', 'keyring'), prompt = FALSE)",
sprintf("ParallelLogger::addDefaultFileLogger(file.path('%s', 'moduleInitLog.txt'))", moduleFolder),
sprintf("ParallelLogger::addDefaultErrorReportLogger(fileName = file.path('%s', 'moduleInitErrorReport.txt'))", moduleFolder),
"renv::restore(prompt = FALSE)"
),
collapse = "\n"
)
tempScriptFile <- tempfile(fileext = ".R")
fileConn <- file(tempScriptFile)
writeLines(script, fileConn)
close(fileConn)

renv::run(
script = tempScriptFile,
job = FALSE,
name = "Buidling renv library",
project = moduleFolder
withModuleRenv(
code = {
ParallelLogger::addDefaultFileLogger(
fileName = file.path(moduleFolder, 'moduleInitLog.txt')
)
ParallelLogger::addDefaultErrorReportLogger(
fileName = file.path(moduleFolder, 'moduleInitErrorReport.txt')
)
renv::restore(prompt = FALSE)
},
moduleFolder = moduleFolder,
injectVars = list(moduleFolder = moduleFolder)
)
success <- TRUE
}
Expand Down

0 comments on commit 0f0c5b1

Please sign in to comment.