diff --git a/R/Execution.R b/R/Execution.R index c2f80ebd..538bd8a3 100644 --- a/R/Execution.R +++ b/R/Execution.R @@ -80,6 +80,61 @@ execute <- function(analysisSpecifications, } } + # Determine if the user has opted to subset to specific modules + # in the analysis specification. If so, validate that the + # modulesToExecute are present in the analysis specification + # before attempting to subset the analyses to run. + if (length(executionSettings$modulesToExecute) > 0) { + # Get the modules in the analysis specification with their + # index in the array + modulesWithIndex <- lapply( + X = seq_along(analysisSpecifications$moduleSpecifications), + FUN = function(i) { + list( + idx = i, + module = analysisSpecifications$moduleSpecifications[[i]]$module + ) + } + ) + modulesInAnalysisSpecification <- sapply( + X = modulesWithIndex, + FUN = function(x) { + x$module + } + ) + + modulesToExecuteString <- paste(executionSettings$modulesToExecute, collapse = ", ") + modulesInAnalysisSpecificationString <- paste(modulesInAnalysisSpecification, collapse = ", ") + + # Stop if we cannot find all of the requested modules + # to execute in the overall analysis specification + if(!all(tolower(executionSettings$modulesToExecute) %in% tolower(modulesInAnalysisSpecification))) { + errorMsg <- paste0( + "The executionSettings specified to run only the modules: ", + modulesToExecuteString, + ".\n However the analysis specification includes the following modules: ", + modulesInAnalysisSpecificationString + ) + stop(errorMsg) + } + + # Subset the analysis specifications to those modules + # specified by the user + cli::cli_alert_info(paste0("Runnning a subset of modules: ", modulesToExecuteString)) + moduleSubset <- unlist( + lapply( + X = modulesWithIndex, + FUN = function(x) { + if (tolower(x$module) %in% tolower(executionSettings$modulesToExecute)) { + return(x$idx) + } + } + ) + ) + analysisSpecifications$moduleSpecifications <- analysisSpecifications$moduleSpecifications[moduleSubset] + } + + # Set up logging if (!dir.exists(dirname(executionSettings$logFileName))) { dir.create(dirname(executionSettings$logFileName), recursive = T) diff --git a/R/Settings.R b/R/Settings.R index 5a9d63ec..1ab44cb2 100644 --- a/R/Settings.R +++ b/R/Settings.R @@ -258,6 +258,8 @@ createEmptyAnalysisSpecificiations <- function() { #' and attempt to pick up where they left off when this value is set to TRUE. #' @param maxCores The maximum number of processing cores to use for execution. The default is to #' use all available cores on the machine. +#' @param modulesToExecute (Optional) A vector with the list of modules to execute. When an empty vector/NULL is supplied (default), +#' all modules in the analysis specification are executed. #' #' @return #' An object of type `ExecutionSettings`. @@ -272,7 +274,8 @@ createCdmExecutionSettings <- function(workDatabaseSchema, logFileName = file.path(resultsFolder, "strategus-log.txt"), minCellCount = 5, incremental = TRUE, - maxCores = parallel::detectCores()) { + maxCores = parallel::detectCores(), + modulesToExecute = c()) { errorMessages <- checkmate::makeAssertCollection() checkmate::assertCharacter(workDatabaseSchema, len = 1, add = errorMessages) checkmate::assertCharacter(cdmDatabaseSchema, len = 1, add = errorMessages) @@ -283,6 +286,7 @@ createCdmExecutionSettings <- function(workDatabaseSchema, checkmate::assertInt(minCellCount, add = errorMessages) checkmate::assertLogical(incremental, add = errorMessages) checkmate::assertInt(maxCores, add = errorMessages) + checkmate::assertVector(modulesToExecute, null.ok = TRUE, add = errorMessages) checkmate::reportAssertions(collection = errorMessages) # Normalize paths to convert relative paths to absolute paths @@ -308,6 +312,9 @@ createCdmExecutionSettings <- function(workDatabaseSchema, #' in results. #' @param maxCores The maximum number of processing cores to use for execution. The default is to #' use all available cores on the machine. +#' @param modulesToExecute (Optional) A vector with the list of modules to execute. When an empty vector/NULL is supplied (default), +#' all modules in the analysis specification are executed. +#' #' @return #' An object of type `ExecutionSettings`. #' @@ -317,7 +324,8 @@ createResultsExecutionSettings <- function(resultsDatabaseSchema, resultsFolder, logFileName = file.path(resultsFolder, "strategus-log.txt"), minCellCount = 5, - maxCores = parallel::detectCores()) { + maxCores = parallel::detectCores(), + modulesToExecute = c()) { errorMessages <- checkmate::makeAssertCollection() checkmate::assertCharacter(resultsDatabaseSchema, len = 1, add = errorMessages) checkmate::assertCharacter(workFolder, len = 1, add = errorMessages) @@ -325,6 +333,7 @@ createResultsExecutionSettings <- function(resultsDatabaseSchema, checkmate::assertCharacter(logFileName, len = 1, add = errorMessages) checkmate::assertInt(minCellCount, add = errorMessages) checkmate::assertInt(maxCores, add = errorMessages) + checkmate::assertVector(modulesToExecute, null.ok = TRUE, add = errorMessages) checkmate::reportAssertions(collection = errorMessages) # Normalize paths to convert relative paths to absolute paths diff --git a/extras/PackageMaintenance.R b/extras/PackageMaintenance.R index 8cecd965..2339e6ce 100644 --- a/extras/PackageMaintenance.R +++ b/extras/PackageMaintenance.R @@ -116,8 +116,7 @@ cdModuleSpecifications <- cdModuleSettingsCreator$createModuleSpecifications( runBreakdownIndexEvents = TRUE, runIncidenceRate = TRUE, runCohortRelationship = TRUE, - runTemporalCohortCharacterization = TRUE, - incremental = FALSE + runTemporalCohortCharacterization = TRUE ) # Cohort Generator ----------------- @@ -448,9 +447,8 @@ cdmModulesAnalysisSpecifications <- createEmptyAnalysisSpecificiations() |> addCharacterizationModuleSpecifications(cModuleSpecifications) |> addCohortDiagnosticsModuleSpecifications(cdModuleSpecifications) |> addCohortGeneratorModuleSpecifications(cgModuleSpecifications) |> - #addCohortIncidenceModuleSpecifications(ciModuleSpecifications) |> + addCohortIncidenceModuleSpecifications(ciModuleSpecifications) |> addCohortMethodeModuleSpecifications(cmModuleSpecifications) |> - #addEvidenceSynthesisModuleSpecifications(evidenceSynthesisAnalysisSpecifications) |> addSelfControlledCaseSeriesModuleSpecifications(sccsModuleSpecifications) |> addPatientLevelPredictionModuleSpecifications(plpModuleSpecifications) diff --git a/inst/testdata/cdmModulesAnalysisSpecifications.json b/inst/testdata/cdmModulesAnalysisSpecifications.json index 0867d091..801d99b4 100644 --- a/inst/testdata/cdmModulesAnalysisSpecifications.json +++ b/inst/testdata/cdmModulesAnalysisSpecifications.json @@ -29,7 +29,7 @@ } ], "subsetDefs": [ - "{\n \"name\": \"test definition\",\n \"definitionId\": 1,\n \"subsetOperators\": [\n {\n \"name\": \"Demographic Criteria\",\n \"subsetType\": \"DemographicSubsetOperator\",\n \"ageMin\": 18,\n \"ageMax\": 64\n }\n ],\n \"packageVersion\": \"0.9.0\",\n \"identifierExpression\": \"targetId * 1000 + definitionId\",\n \"operatorNameConcatString\": \", \",\n \"subsetCohortNameTemplate\": \"@baseCohortName - @subsetDefinitionName @operatorNames\"\n}" + "{\n \"name\": \"test definition\",\n \"definitionId\": 1,\n \"subsetOperators\": [\n {\n \"name\": \"Demographic Criteria\",\n \"subsetType\": \"DemographicSubsetOperator\",\n \"ageMin\": 18,\n \"ageMax\": 64\n }\n ],\n \"packageVersion\": \"0.11.0\",\n \"identifierExpression\": \"targetId * 1000 + definitionId\",\n \"operatorNameConcatString\": \", \",\n \"subsetCohortNameTemplate\": \"@baseCohortName - @subsetDefinitionName @operatorNames\"\n}" ], "cohortSubsets": [ { @@ -254,125 +254,176 @@ { "module": "CharacterizationModule", "settings": { - "timeToEventSettings": [ - { - "targetIds": [1, 2], - "outcomeIds": 3, - "attr_class": "timeToEventSettings" - } - ], - "dechallengeRechallengeSettings": [ - { - "targetCohortDefinitionIds": [1, 2], - "outcomeCohortDefinitionIds": 3, - "dechallengeStopInterval": 30, - "dechallengeEvaluationWindow": 30, - "attr_class": "dechallengeRechallengeSettings" - } - ], - "aggregateCovariateSettings": [ - { - "targetIds": [1, 2], - "outcomeIds": 3, - "minPriorObservation": 0, - "riskWindowStart": 1, - "startAnchor": "cohort start", - "riskWindowEnd": 0, - "endAnchor": "cohort end", - "covariateSettings": { - "temporal": false, - "temporalSequence": false, - "DemographicsGender": true, - "DemographicsAgeGroup": true, - "DemographicsRace": true, - "DemographicsEthnicity": true, - "DemographicsIndexYear": true, - "DemographicsIndexMonth": true, - "ConditionGroupEraLongTerm": true, - "ConditionGroupEraShortTerm": true, - "DrugGroupEraLongTerm": true, - "DrugGroupEraShortTerm": true, - "DrugGroupEraOverlapping": true, - "ProcedureOccurrenceLongTerm": true, - "ProcedureOccurrenceShortTerm": true, - "DeviceExposureLongTerm": true, - "DeviceExposureShortTerm": true, - "MeasurementLongTerm": true, - "MeasurementShortTerm": true, - "MeasurementRangeGroupLongTerm": true, - "ObservationLongTerm": true, - "ObservationShortTerm": true, - "CharlsonIndex": true, - "Dcsi": true, - "Chads2": true, - "Chads2Vasc": true, - "includedCovariateConceptIds": [], - "includedCovariateIds": [], - "addDescendantsToInclude": false, - "excludedCovariateConceptIds": [], - "addDescendantsToExclude": false, - "shortTermStartDays": -30, - "mediumTermStartDays": -180, - "endDays": 0, - "longTermStartDays": -365, - "attr_class": "covariateSettings", - "attr_fun": "getDbDefaultCovariateData" - }, - "minCharacterizationMean": 0, - "attr_class": "aggregateCovariateSettings" - }, - { - "targetIds": [1, 2], - "outcomeIds": 3, - "minPriorObservation": 0, - "riskWindowStart": 1, - "startAnchor": "cohort start", - "riskWindowEnd": 365, - "endAnchor": "cohort end", - "covariateSettings": { - "temporal": false, - "temporalSequence": false, - "DemographicsGender": true, - "DemographicsAgeGroup": true, - "DemographicsRace": true, - "DemographicsEthnicity": true, - "DemographicsIndexYear": true, - "DemographicsIndexMonth": true, - "ConditionGroupEraLongTerm": true, - "ConditionGroupEraShortTerm": true, - "DrugGroupEraLongTerm": true, - "DrugGroupEraShortTerm": true, - "DrugGroupEraOverlapping": true, - "ProcedureOccurrenceLongTerm": true, - "ProcedureOccurrenceShortTerm": true, - "DeviceExposureLongTerm": true, - "DeviceExposureShortTerm": true, - "MeasurementLongTerm": true, - "MeasurementShortTerm": true, - "MeasurementRangeGroupLongTerm": true, - "ObservationLongTerm": true, - "ObservationShortTerm": true, - "CharlsonIndex": true, - "Dcsi": true, - "Chads2": true, - "Chads2Vasc": true, - "includedCovariateConceptIds": [], - "includedCovariateIds": [], - "addDescendantsToInclude": false, - "excludedCovariateConceptIds": [], - "addDescendantsToExclude": false, - "shortTermStartDays": -30, - "mediumTermStartDays": -180, - "endDays": 0, - "longTermStartDays": -365, - "attr_class": "covariateSettings", - "attr_fun": "getDbDefaultCovariateData" + "analysis": { + "timeToEventSettings": [ + { + "targetIds": [1, 2], + "outcomeIds": 3, + "attr_class": "timeToEventSettings" + } + ], + "dechallengeRechallengeSettings": [ + { + "targetCohortDefinitionIds": [1, 2], + "outcomeCohortDefinitionIds": 3, + "dechallengeStopInterval": 30, + "dechallengeEvaluationWindow": 30, + "attr_class": "dechallengeRechallengeSettings" + } + ], + "aggregateCovariateSettings": [ + { + "targetIds": [1, 2], + "minPriorObservation": 365, + "outcomeIds": 3, + "outcomeWashoutDays": 365, + "riskWindowStart": 1, + "startAnchor": "cohort start", + "riskWindowEnd": 0, + "endAnchor": "cohort end", + "covariateSettings": [ + { + "temporal": false, + "temporalSequence": false, + "DemographicsGender": true, + "DemographicsAge": true, + "DemographicsAgeGroup": true, + "DemographicsRace": true, + "DemographicsEthnicity": true, + "DemographicsIndexYear": true, + "DemographicsIndexMonth": true, + "DemographicsPriorObservationTime": true, + "DemographicsPostObservationTime": true, + "DemographicsTimeInCohort": true, + "ConditionGroupEraLongTerm": true, + "ConditionGroupEraShortTerm": true, + "DrugGroupEraLongTerm": true, + "DrugGroupEraShortTerm": true, + "DrugGroupEraOverlapping": true, + "ProcedureOccurrenceLongTerm": true, + "ProcedureOccurrenceShortTerm": true, + "DeviceExposureLongTerm": true, + "DeviceExposureShortTerm": true, + "MeasurementLongTerm": true, + "MeasurementShortTerm": true, + "ObservationLongTerm": true, + "ObservationShortTerm": true, + "VisitConceptCountLongTerm": true, + "VisitConceptCountShortTerm": true, + "longTermStartDays": -365, + "mediumTermStartDays": -180, + "shortTermStartDays": -30, + "endDays": 0, + "includedCovariateConceptIds": [], + "addDescendantsToInclude": false, + "excludedCovariateConceptIds": [], + "addDescendantsToExclude": false, + "includedCovariateIds": [], + "attr_class": "covariateSettings", + "attr_fun": "getDbDefaultCovariateData" + } + ], + "caseCovariateSettings": { + "temporal": false, + "temporalSequence": false, + "ConditionGroupEraDuring": true, + "DrugGroupEraDuring": true, + "ProcedureOccurrenceDuring": true, + "DeviceExposureDuring": true, + "MeasurementDuring": true, + "ObservationDuring": true, + "VisitConceptCountDuring": true, + "includedCovariateConceptIds": [], + "addDescendantsToInclude": false, + "excludedCovariateConceptIds": [], + "addDescendantsToExclude": false, + "includedCovariateIds": [], + "attr_class": "covariateSettings", + "attr_fun": "Characterization::getDbDuringCovariateData" + }, + "casePreTargetDuration": 365, + "casePostOutcomeDuration": 365, + "extractNonCaseCovariates": true, + "attr_class": "aggregateCovariateSettings" }, - "minCharacterizationMean": 0, - "attr_class": "aggregateCovariateSettings" - } - ], - "attr_class": "characterizationSettings" + { + "targetIds": [1, 2], + "minPriorObservation": 365, + "outcomeIds": 3, + "outcomeWashoutDays": 365, + "riskWindowStart": 1, + "startAnchor": "cohort start", + "riskWindowEnd": 365, + "endAnchor": "cohort end", + "covariateSettings": [ + { + "temporal": false, + "temporalSequence": false, + "DemographicsGender": true, + "DemographicsAge": true, + "DemographicsAgeGroup": true, + "DemographicsRace": true, + "DemographicsEthnicity": true, + "DemographicsIndexYear": true, + "DemographicsIndexMonth": true, + "DemographicsPriorObservationTime": true, + "DemographicsPostObservationTime": true, + "DemographicsTimeInCohort": true, + "ConditionGroupEraLongTerm": true, + "ConditionGroupEraShortTerm": true, + "DrugGroupEraLongTerm": true, + "DrugGroupEraShortTerm": true, + "DrugGroupEraOverlapping": true, + "ProcedureOccurrenceLongTerm": true, + "ProcedureOccurrenceShortTerm": true, + "DeviceExposureLongTerm": true, + "DeviceExposureShortTerm": true, + "MeasurementLongTerm": true, + "MeasurementShortTerm": true, + "ObservationLongTerm": true, + "ObservationShortTerm": true, + "VisitConceptCountLongTerm": true, + "VisitConceptCountShortTerm": true, + "longTermStartDays": -365, + "mediumTermStartDays": -180, + "shortTermStartDays": -30, + "endDays": 0, + "includedCovariateConceptIds": [], + "addDescendantsToInclude": false, + "excludedCovariateConceptIds": [], + "addDescendantsToExclude": false, + "includedCovariateIds": [], + "attr_class": "covariateSettings", + "attr_fun": "getDbDefaultCovariateData" + } + ], + "caseCovariateSettings": { + "temporal": false, + "temporalSequence": false, + "ConditionGroupEraDuring": true, + "DrugGroupEraDuring": true, + "ProcedureOccurrenceDuring": true, + "DeviceExposureDuring": true, + "MeasurementDuring": true, + "ObservationDuring": true, + "VisitConceptCountDuring": true, + "includedCovariateConceptIds": [], + "addDescendantsToInclude": false, + "excludedCovariateConceptIds": [], + "addDescendantsToExclude": false, + "includedCovariateIds": [], + "attr_class": "covariateSettings", + "attr_fun": "Characterization::getDbDuringCovariateData" + }, + "casePreTargetDuration": 365, + "casePostOutcomeDuration": 365, + "extractNonCaseCovariates": true, + "attr_class": "aggregateCovariateSettings" + } + ], + "attr_class": "characterizationSettings" + }, + "minCharacterizationMean": 0.01 }, "attr_class": ["ModuleSpecifications", "CharacterizationModuleSpecifications"] }, @@ -427,19 +478,87 @@ "attr_fun": "getDbDefaultCovariateData" }, "minCharacterizationMean": 0.01, - "irWashoutPeriod": 0, - "incremental": false + "irWashoutPeriod": 0 }, "attr_class": ["ModuleSpecifications", "CohortDiagnosticsModuleSpecifications"] }, { "module": "CohortGeneratorModule", "settings": { - "incremental": true, "generateStats": true }, "attr_class": ["ModuleSpecifications", "CohortGeneratorModuleSpecifications"] }, + { + "module": "CohortIncidenceModule", + "settings": { + "irDesign": { + "targetDefs": [ + { + "id": 1, + "name": "Celecoxib" + }, + { + "id": 2, + "name": "Diclofenac" + }, + { + "id": 4, + "name": "Celecoxib Age >= 30" + }, + { + "id": 5, + "name": "Diclofenac Age >= 30" + } + ], + "outcomeDefs": [ + { + "id": 1, + "name": "GI bleed", + "cohortId": 3, + "cleanWindow": 9999 + } + ], + "timeAtRiskDefs": [ + { + "id": 1, + "start": { + "dateField": "start", + "offset": 0 + }, + "end": { + "dateField": "end", + "offset": 0 + } + }, + { + "id": 2, + "start": { + "dateField": "start", + "offset": 0 + }, + "end": { + "dateField": "start", + "offset": 365 + } + } + ], + "analysisList": [ + { + "targets": [1, 2, 4, 5], + "outcomes": 1, + "tars": [1, 2] + } + ], + "strataSettings": { + "byAge": false, + "byGender": true, + "byYear": true + } + } + }, + "attr_class": ["ModuleSpecifications", "CohortIncidenceModuleSpecifications"] + }, { "module": "CohortMethodModule", "settings": { @@ -476,8 +595,13 @@ "MeasurementLongTerm": true, "MeasurementShortTerm": true, "MeasurementRangeGroupLongTerm": true, + "MeasurementRangeGroupShortTerm": true, + "MeasurementValueAsConceptLongTerm": true, + "MeasurementValueAsConceptShortTerm": true, "ObservationLongTerm": true, "ObservationShortTerm": true, + "ObservationValueAsConceptLongTerm": true, + "ObservationValueAsConceptShortTerm": true, "CharlsonIndex": true, "Dcsi": true, "Chads2": true, @@ -590,8 +714,13 @@ "MeasurementLongTerm": true, "MeasurementShortTerm": true, "MeasurementRangeGroupLongTerm": true, + "MeasurementRangeGroupShortTerm": true, + "MeasurementValueAsConceptLongTerm": true, + "MeasurementValueAsConceptShortTerm": true, "ObservationLongTerm": true, "ObservationShortTerm": true, + "ObservationValueAsConceptLongTerm": true, + "ObservationValueAsConceptShortTerm": true, "CharlsonIndex": true, "Dcsi": true, "Chads2": true, @@ -2348,8 +2477,13 @@ "MeasurementLongTerm": true, "MeasurementShortTerm": true, "MeasurementRangeGroupLongTerm": true, + "MeasurementRangeGroupShortTerm": true, + "MeasurementValueAsConceptLongTerm": true, + "MeasurementValueAsConceptShortTerm": true, "ObservationLongTerm": true, "ObservationShortTerm": true, + "ObservationValueAsConceptLongTerm": true, + "ObservationValueAsConceptShortTerm": true, "CharlsonIndex": true, "Dcsi": true, "Chads2": true, @@ -2422,7 +2556,7 @@ "modelType": "logistic", "addIntercept": true, "useControl": true, - "seed": 99660466, + "seed": 59989126, "name": "Lasso Logistic Regression", "threads": -1, "tolerance": 2e-06, @@ -2437,7 +2571,7 @@ "splitSettings": { "test": 0.25, "train": 0.75, - "seed": 98421, + "seed": 30365, "nfold": 3, "attr_class": "splitSettings", "attr_fun": "randomSplitter" @@ -2485,8 +2619,13 @@ "MeasurementLongTerm": true, "MeasurementShortTerm": true, "MeasurementRangeGroupLongTerm": true, + "MeasurementRangeGroupShortTerm": true, + "MeasurementValueAsConceptLongTerm": true, + "MeasurementValueAsConceptShortTerm": true, "ObservationLongTerm": true, "ObservationShortTerm": true, + "ObservationValueAsConceptLongTerm": true, + "ObservationValueAsConceptShortTerm": true, "CharlsonIndex": true, "Dcsi": true, "Chads2": true, @@ -2559,7 +2698,7 @@ "modelType": "logistic", "addIntercept": true, "useControl": true, - "seed": 61501935, + "seed": 63310743, "name": "Lasso Logistic Regression", "threads": -1, "tolerance": 2e-06, @@ -2574,7 +2713,7 @@ "splitSettings": { "test": 0.25, "train": 0.75, - "seed": 56231, + "seed": 69669, "nfold": 3, "attr_class": "splitSettings", "attr_fun": "randomSplitter" diff --git a/man/createCdmExecutionSettings.Rd b/man/createCdmExecutionSettings.Rd index e54e6544..e90caa61 100644 --- a/man/createCdmExecutionSettings.Rd +++ b/man/createCdmExecutionSettings.Rd @@ -14,7 +14,8 @@ createCdmExecutionSettings( logFileName = file.path(resultsFolder, "strategus-log.txt"), minCellCount = 5, incremental = TRUE, - maxCores = parallel::detectCores() + maxCores = parallel::detectCores(), + modulesToExecute = c() ) } \arguments{ @@ -45,6 +46,9 @@ and attempt to pick up where they left off when this value is set to TRUE.} \item{maxCores}{The maximum number of processing cores to use for execution. The default is to use all available cores on the machine.} + +\item{modulesToExecute}{(Optional) A vector with the list of modules to execute. When an empty vector/NULL is supplied (default), +all modules in the analysis specification are executed.} } \value{ An object of type \code{ExecutionSettings}. diff --git a/man/createResultsExecutionSettings.Rd b/man/createResultsExecutionSettings.Rd index 883e0487..52ce80c2 100644 --- a/man/createResultsExecutionSettings.Rd +++ b/man/createResultsExecutionSettings.Rd @@ -10,7 +10,8 @@ createResultsExecutionSettings( resultsFolder, logFileName = file.path(resultsFolder, "strategus-log.txt"), minCellCount = 5, - maxCores = parallel::detectCores() + maxCores = parallel::detectCores(), + modulesToExecute = c() ) } \arguments{ @@ -27,6 +28,9 @@ in results.} \item{maxCores}{The maximum number of processing cores to use for execution. The default is to use all available cores on the machine.} + +\item{modulesToExecute}{(Optional) A vector with the list of modules to execute. When an empty vector/NULL is supplied (default), +all modules in the analysis specification are executed.} } \value{ An object of type \code{ExecutionSettings}. diff --git a/tests/testthat/test-Execution.R b/tests/testthat/test-Execution.R index 64da5c65..460b0d70 100644 --- a/tests/testthat/test-Execution.R +++ b/tests/testthat/test-Execution.R @@ -211,3 +211,75 @@ test_that("Negative control outcomes are optional", { ignore.case = TRUE ) }) + +test_that("Specify subset of modules to run with modules not in specification fails", { + analysisSpecifications <- ParallelLogger::loadSettingsFromJson( + fileName = system.file("testdata/cdmModulesAnalysisSpecifications.json", + package = "Strategus" + ) + ) + executionSettings <- createCdmExecutionSettings( + workDatabaseSchema = workDatabaseSchema, + cdmDatabaseSchema = cdmDatabaseSchema, + cohortTableNames = CohortGenerator::getCohortTableNames(cohortTable = "unit_test"), + workFolder = file.path(tempDir, "work_folder"), + resultsFolder = file.path(tempDir, "results_folder"), + modulesToExecute = c("foobar") + ) + + expect_error( + Strategus::execute( + connectionDetails = connectionDetails, + analysisSpecifications = analysisSpecifications, + executionSettings = executionSettings + ) + ) + + executionSettings <- createResultsExecutionSettings( + resultsDatabaseSchema = "main", + workFolder = file.path(tempDir, "work_folder"), + resultsFolder = file.path(tempDir, "results_folder"), + modulesToExecute = c("foobar") + ) + + expect_error( + Strategus::execute( + connectionDetails = connectionDetails, + analysisSpecifications = analysisSpecifications, + executionSettings = executionSettings + ) + ) +}) + +test_that("Specify subset of modules to run", { + analysisSpecifications <- ParallelLogger::loadSettingsFromJson( + fileName = system.file("testdata/cdmModulesAnalysisSpecifications.json", + package = "Strategus" + ) + ) + + modulesToExecute <- c("CohortGeneratorModule", "CohortIncidenceModule") + executionSettings <- createCdmExecutionSettings( + workDatabaseSchema = workDatabaseSchema, + cdmDatabaseSchema = cdmDatabaseSchema, + cohortTableNames = CohortGenerator::getCohortTableNames(cohortTable = "unit_test"), + workFolder = file.path(tempDir, "work_folder"), + resultsFolder = file.path(tempDir, "results_folder"), + modulesToExecute = modulesToExecute + ) + + output <- Strategus::execute( + connectionDetails = connectionDetails, + analysisSpecifications = analysisSpecifications, + executionSettings = executionSettings + ) + + modulesExecuted <- sapply( + X = output, + FUN = function(x) { + x$moduleName + } + ) + + expect_true(all(modulesExecuted %in% modulesToExecute)) +})