Skip to content

Commit

Permalink
Add integer treatment settings for DatabaseConnector to execution set…
Browse files Browse the repository at this point in the history
…tings
  • Loading branch information
anthonysena committed Sep 5, 2023
1 parent f52da0d commit 06ca01d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 3 deletions.
2 changes: 2 additions & 0 deletions R/RunModule.R
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ runModule <- function(analysisSpecifications, keyringSettings, moduleIndex, exec

options(andromedaTempFolder = file.path(jobContext$moduleExecutionSettings$workFolder, 'andromedaTemp'))
options(tempEmulationSchema = jobContext$moduleExecutionSettings$tempEmulationSchema)
options(databaseConnectorIntegerAsNumeric = jobContext$moduleExecutionSettings$integerAsNumeric)
options(databaseConnectorInteger64AsNumeric = jobContext$moduleExecutionSettings$integer64AsNumeric)

if (Sys.getenv('FORCE_RENV_USE', '') == 'TRUE') {
renv::use(lockfile = 'renv.lock')
Expand Down
20 changes: 18 additions & 2 deletions R/Settings.R
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ addModuleSpecifications <- function(analysisSpecifications, moduleSpecifications
#' @param resultsFolder A folder in the local file system where the module output will be written.
#' @param minCellCount The minimum number of subjects contributing to a count before it can be included
#' in results.
#' @param integerAsNumeric Logical: should 32-bit integers be converted to numeric (double) values? If FALSE 32-bit integers will be represented using R's native `Integer` class. Default is TRUE
#' @param integer64AsNumeric Logical: should 64-bit integers be converted to numeric (double) values? If FALSE 64-bit integers will be represented using `bit64::integer64`. Default is TRUE
#' @param resultsConnectionDetailsReference A string that can be used to retrieve the results database connection
#' details from a secure local store.
#' @param resultsDatabaseSchema A schema where the results tables are stored
Expand All @@ -108,6 +110,8 @@ createCdmExecutionSettings <- function(connectionDetailsReference,
workFolder,
resultsFolder,
minCellCount = 5,
integerAsNumeric = getOption("databaseConnectorIntegerAsNumeric", default = TRUE),
integer64AsNumeric = getOption("databaseConnectorInteger64AsNumeric", default = TRUE),
resultsConnectionDetailsReference = NULL,
resultsDatabaseSchema = NULL) {
errorMessages <- checkmate::makeAssertCollection()
Expand All @@ -118,6 +122,8 @@ createCdmExecutionSettings <- function(connectionDetailsReference,
checkmate::assertCharacter(workFolder, len = 1, add = errorMessages)
checkmate::assertCharacter(resultsFolder, len = 1, add = errorMessages)
checkmate::assertInt(minCellCount, add = errorMessages)
checkmate::assertLogical(integerAsNumeric, max.len = 1, add = errorMessages)
checkmate::assertLogical(integer64AsNumeric, max.len = 1, add = errorMessages)
checkmate::assertCharacter(resultsConnectionDetailsReference, null.ok = TRUE, add = errorMessages)
checkmate::assertCharacter(resultsDatabaseSchema, null.ok = TRUE, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)
Expand All @@ -131,6 +137,8 @@ createCdmExecutionSettings <- function(connectionDetailsReference,
workFolder = workFolder,
resultsFolder = resultsFolder,
minCellCount = minCellCount,
integerAsNumeric = integerAsNumeric,
integer64AsNumeric = integer64AsNumeric,
resultsConnectionDetailsReference = resultsConnectionDetailsReference,
resultsDatabaseSchema = resultsDatabaseSchema
)
Expand All @@ -147,6 +155,8 @@ createCdmExecutionSettings <- function(connectionDetailsReference,
#' @param resultsFolder A folder in the local file system where the module output will be written.
#' @param minCellCount The minimum number of subjects contributing to a count before it can be included
#' in results.
#' @param integerAsNumeric Logical: should 32-bit integers be converted to numeric (double) values? If FALSE 32-bit integers will be represented using R's native `Integer` class. Default is TRUE
#' @param integer64AsNumeric Logical: should 64-bit integers be converted to numeric (double) values? If FALSE 64-bit integers will be represented using `bit64::integer64`. Default is TRUE
#'
#' @return
#' An object of type `ExecutionSettings`.
Expand All @@ -156,21 +166,27 @@ createResultsExecutionSettings <- function(resultsConnectionDetailsReference,
resultsDatabaseSchema,
workFolder,
resultsFolder,
minCellCount = 5) {
minCellCount = 5,
integerAsNumeric = getOption("databaseConnectorIntegerAsNumeric", default = TRUE),
integer64AsNumeric = getOption("databaseConnectorInteger64AsNumeric", default = TRUE)) {
errorMessages <- checkmate::makeAssertCollection()
checkmate::assertCharacter(resultsConnectionDetailsReference, len = 1, add = errorMessages)
checkmate::assertCharacter(resultsDatabaseSchema, len = 1, add = errorMessages)
checkmate::assertCharacter(workFolder, len = 1, add = errorMessages)
checkmate::assertCharacter(resultsFolder, len = 1, add = errorMessages)
checkmate::assertInt(minCellCount, add = errorMessages)
checkmate::assertLogical(integerAsNumeric, max.len = 1, add = errorMessages)
checkmate::assertLogical(integer64AsNumeric, max.len = 1, add = errorMessages)
checkmate::reportAssertions(collection = errorMessages)

executionSettings <- list(
resultsConnectionDetailsReference = resultsConnectionDetailsReference,
resultsDatabaseSchema = resultsDatabaseSchema,
workFolder = workFolder,
resultsFolder = resultsFolder,
minCellCount = minCellCount
minCellCount = minCellCount,
integerAsNumeric = integerAsNumeric,
integer64AsNumeric = integer64AsNumeric
)
class(executionSettings) <- c("ResultsExecutionSettings", "ExecutionSettings")
return(executionSettings)
Expand Down
6 changes: 6 additions & 0 deletions man/createCdmExecutionSettings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 7 additions & 1 deletion man/createResultsExecutionSettings.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 06ca01d

Please sign in to comment.