diff --git a/R/DatabaseMetaData.R b/R/DatabaseMetaData.R index cdd775f3..bf73d02d 100644 --- a/R/DatabaseMetaData.R +++ b/R/DatabaseMetaData.R @@ -42,7 +42,7 @@ createDatabaseMetaData <- function(executionSettings, keyringName = NULL) { connection = connection, databaseSchema = executionSettings$cdmDatabaseSchema ) - cdmTableList <- tolower(cdmTableList) + cdmTableList <- unique(tolower(cdmTableList)) if (!length(cdmTableList[which(x = cdmTableList %in% requiredTables)]) == length(requiredTables)) { missingCdmTables <- requiredTables[!(requiredTables %in% cdmTableList)] diff --git a/R/Execution.R b/R/Execution.R index afc32cf5..3158ecb4 100644 --- a/R/Execution.R +++ b/R/Execution.R @@ -53,6 +53,17 @@ execute <- function(analysisSpecifications, checkmate::assertChoice(x = keyringName, choices = keyringList$keyring, null.ok = TRUE, add = errorMessages) checkmate::reportAssertions(collection = errorMessages) + # Assert that the temp emulation schema is set if required for the dbms + # specified by the executionSettings + connectionDetails <- retrieveConnectionDetails( + connectionDetailsReference = executionSettings$connectionDetailsReference, + keyringName = keyringName + ) + DatabaseConnector::assertTempEmulationSchemaSet( + dbms = connectionDetails$dbms, + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema") + ) + modules <- ensureAllModulesInstantiated(analysisSpecifications) if (is.null(executionScriptFolder)) { diff --git a/R/ModuleInstantiation.R b/R/ModuleInstantiation.R index a37cdf98..55b7e715 100644 --- a/R/ModuleInstantiation.R +++ b/R/ModuleInstantiation.R @@ -191,15 +191,15 @@ instantiateModule <- function(module, version, remoteRepo, remoteUsername, modul stop(message) } - script <- " - renv::restore(prompt = FALSE) - if (!require('ParallelLogger', quietly = TRUE)) { - install.packages('ParallelLogger') - } - if (!require('keyring', quietly = TRUE)) { - install.packages('keyring') - } - " + 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.R'))", moduleFolder), + "renv::restore(prompt = FALSE)" + ), + collapse = "\n" + ) tempScriptFile <- tempfile(fileext = ".R") fileConn <- file(tempScriptFile) writeLines(script, fileConn) diff --git a/R/RunModule.R b/R/RunModule.R index 258cb1fb..e3e4cce2 100644 --- a/R/RunModule.R +++ b/R/RunModule.R @@ -88,6 +88,8 @@ runModule <- function(analysisSpecifications, keyringSettings, moduleIndex, exec options(andromedaTempFolder = file.path(jobContext$moduleExecutionSettings$workFolder, 'andromedaTemp')) + options(tempEmulationSchema = jobContext$moduleExecutionSettings$tempEmulationSchema) + if (Sys.getenv('FORCE_RENV_USE', '') == 'TRUE') { renv::use(lockfile = 'renv.lock') } diff --git a/R/Settings.R b/R/Settings.R index dc021e54..6ae54d42 100644 --- a/R/Settings.R +++ b/R/Settings.R @@ -103,6 +103,7 @@ createCdmExecutionSettings <- function(connectionDetailsReference, workDatabaseSchema, cdmDatabaseSchema, cohortTableNames = CohortGenerator::getCohortTableNames(cohortTable = "cohort"), + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), workFolder, resultsFolder, minCellCount = 5, @@ -125,6 +126,7 @@ createCdmExecutionSettings <- function(connectionDetailsReference, workDatabaseSchema = workDatabaseSchema, cdmDatabaseSchema = cdmDatabaseSchema, cohortTableNames = cohortTableNames, + tempEmulationSchema = tempEmulationSchema, workFolder = workFolder, resultsFolder = resultsFolder, minCellCount = minCellCount, @@ -214,7 +216,7 @@ storeConnectionDetails <- function(connectionDetails, connectionDetailsReference if (is.function(connectionDetails[[i]])) { detail <- connectionDetails[[i]]() if (is.null(detail)) { - connectionDetails[[i]] <- "" + connectionDetails[[i]] <- list(NULL) # Fixes Issue #74 } else { connectionDetails[[i]] <- connectionDetails[[i]]() } diff --git a/inst/testdata/analysisSpecification.json b/inst/testdata/analysisSpecification.json index 53fc459a..efb11134 100644 --- a/inst/testdata/analysisSpecification.json +++ b/inst/testdata/analysisSpecification.json @@ -223,7 +223,7 @@ "moduleSpecifications": [ { "module": "CohortGeneratorModule", - "version": "0.1.0", + "version": "0.1.1-1", "remoteRepo": "github.com", "remoteUsername": "ohdsi", "settings": { diff --git a/man/Strategus-package.Rd b/man/Strategus-package.Rd index ce39d968..94d241d6 100644 --- a/man/Strategus-package.Rd +++ b/man/Strategus-package.Rd @@ -23,6 +23,7 @@ Useful links: Authors: \itemize{ \item Anthony Sena \email{sena@ohdsi.org} + \item Jamie Gilbert } Other contributors: diff --git a/man/createCdmExecutionSettings.Rd b/man/createCdmExecutionSettings.Rd index c04d3d6d..c8d447ba 100644 --- a/man/createCdmExecutionSettings.Rd +++ b/man/createCdmExecutionSettings.Rd @@ -9,6 +9,7 @@ createCdmExecutionSettings( workDatabaseSchema, cdmDatabaseSchema, cohortTableNames = CohortGenerator::getCohortTableNames(cohortTable = "cohort"), + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), workFolder, resultsFolder, minCellCount = 5, diff --git a/man/withModuleRenv.Rd b/man/withModuleRenv.Rd new file mode 100644 index 00000000..64afb036 --- /dev/null +++ b/man/withModuleRenv.Rd @@ -0,0 +1,42 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/ModuleEnv.R +\name{withModuleRenv} +\alias{withModuleRenv} +\title{Load module execution space inside and renv +inspired by targets::tar_script but allowing custom variable execution} +\usage{ +withModuleRenv( + code, + moduleFolder, + injectVars = list(), + tempScriptFile = tempfile(fileext = ".R"), + useLocalStrategusLibrary = TRUE, + job = FALSE, + processName = paste(moduleFolder, "_renv_run") +) +} +\arguments{ +\item{code}{code block to execute} + +\item{moduleFolder}{Instantiated Strategus module folder} + +\item{injectVars}{list of var names list(name=value) to replace (e.g. replace list(foo = "some string") will +find the pattern foo and replace it with the string some string - be careful!} + +\item{tempScriptFile}{tempFile to write script to (ret} + +\item{job}{run as rstudio job} + +\item{processName}{String name for process} +} +\value{ +NULL invisibly +} +\description{ +Designed to allow more human readable code that is executed inside a module as well as simple variable substituion +for injecting constants (e.g. simple parameters or file paths used inside and outside of modules) +} +\details{ +This pattern also allows dependency injection which could be used if you don't want to use and renv and (instead) +would like to use docker images or just execution in the base environment for testing/debugging +}