diff --git a/R/Execution.R b/R/Execution.R index 3be40be1..0322201a 100644 --- a/R/Execution.R +++ b/R/Execution.R @@ -24,18 +24,13 @@ #' Execute analysis specifications. #' #' @template AnalysisSpecifications -#' @param executionSettings An object of type `ExecutionSettings` as created -#' by [createCdmExecutionSettings()] or [createResultsExecutionSettings()]. +#' @template executionSettings #' @param executionScriptFolder Optional: the path to use for storing the execution script. #' when NULL, this function will use a temporary #' file location to create the script to execute. -#' #' @template keyringName -#' #' @param restart Restart run? Requires `executionScriptFolder` to be specified, and be #' the same as the `executionScriptFolder` used in the run to restart. -#' -#' #' @return #' Does not return anything. Is called for the side-effect of executing the specified #' analyses. @@ -115,14 +110,13 @@ generateTargetsScript <- function(analysisSpecifications, executionSettings, dep moduleToTargetNames <- readRDS(moduleToTargetNamesFileName) dependencies <- readRDS(dependenciesFileName) - library(dplyr) - targets::tar_option_set(packages = c("Strategus", "keyring"), imports = c("Strategus", "keyring")) - targetList <- list( - targets::tar_target(analysisSpecifications, readRDS(analysisSpecificationsFileName)), - # NOTE Execution settings could be mapped to many different cdms making re-execution across cdms much simpler - targets::tar_target(executionSettings, readRDS(executionSettingsFileName)), - targets::tar_target(keyringSettings, readRDS(keyringSettingsFileName)) - ) + targets::tar_option_set(packages = c("Strategus", "keyring"), imports = c("Strategus", "keyring")) + targetList <- list( + targets::tar_target(analysisSpecifications, readRDS(analysisSpecificationsFileName)), + # NOTE Execution settings could be mapped to many different cdms making re-execution across cdms much simpler + targets::tar_target(executionSettings, readRDS(executionSettingsFileName)), + targets::tar_target(keyringSettings, readRDS(keyringSettingsFileName)) + ) # factory for producing module targets based on their dependencies # This could be inside Strategus as an exported function @@ -132,13 +126,15 @@ generateTargetsScript <- function(analysisSpecifications, executionSettings, dep for (i in 1:length(analysisSpecificationsLoad$moduleSpecifications)) { moduleSpecification <- analysisSpecificationsLoad$moduleSpecifications[[i]] targetName <- sprintf("%s_%d", moduleSpecification$module, i) - dependencyModules <- dependencies %>% - filter(.data$module == moduleSpecification$module) %>% - pull(.data$dependsOn) - - dependencyTargetNames <- moduleToTargetNames %>% - filter(.data$module %in% dependencyModules) %>% - pull(.data$targetName) + dependencyModules <- dependencies[dependencies$module == moduleSpecification$module,]$dependsOn + #%>% + #filter(.data$module == moduleSpecification$module) %>% + #pull(.data$dependsOn) + + dependencyTargetNames <- moduleToTargetNames[moduleToTargetNames$module %in% dependencyModules,]$targetName + #%>% + # filter(.data$module %in% dependencyModules) %>% + # pull(.data$targetName) # Use of tar_target_raw allows dynamic names targetList[[length(targetList) + 1]] <- targets::tar_target_raw(targetName, diff --git a/R/ResultModelCreation.R b/R/ResultModelCreation.R index dc3c658e..78f988d4 100644 --- a/R/ResultModelCreation.R +++ b/R/ResultModelCreation.R @@ -21,6 +21,7 @@ #' If recreate is set to TRUE all existing data will be removed, otherwise #' #' @inheritParams execute +#' #' @export createResultDataModels <- function(analysisSpecifications, executionSettings, @@ -58,13 +59,12 @@ createResultDataModels <- function(analysisSpecifications, ## analysisSpecificationsLoad <- readRDS(analysisSpecificationsFileName) - library(dplyr) - targets::tar_option_set(packages = c("Strategus", "keyring"), imports = c("Strategus", "keyring")) - targetList <- list( - targets::tar_target(analysisSpecifications, readRDS(analysisSpecificationsFileName)), - targets::tar_target(executionSettings, readRDS(executionSettingsFileName)), - targets::tar_target(keyringSettings, readRDS(keyringSettingsFileName)) - ) + targets::tar_option_set(packages = c("Strategus", "keyring"), imports = c("Strategus", "keyring")) + targetList <- list( + targets::tar_target(analysisSpecifications, readRDS(analysisSpecificationsFileName)), + targets::tar_target(executionSettings, readRDS(executionSettingsFileName)), + targets::tar_target(keyringSettings, readRDS(keyringSettingsFileName)) + ) for (i in 1:length(analysisSpecificationsLoad$moduleSpecifications)) { moduleSpecification <- analysisSpecificationsLoad$moduleSpecifications[[i]] @@ -118,7 +118,20 @@ createResultDataModels <- function(analysisSpecifications, } -#' Results upload callbacks for inserting results in to a database +#' Create module(s) result data model +#' @description +#' This function will create the results data model for the modules in the +#' `analysisSpecifications`. A module can implement its own results data model +#' creation function by implementing the function `createDataModelSchema` in +#' its Main.R. The default behavior is to use the `ResultsModelManager` to create +#' the results data model based on the `resultsDataModelSpecification.csv` in the +#' module's results folder. +#' +#' @template AnalysisSpecifications +#' @param keyringSettings The keyringSettings from the executionSettings context +#' @param moduleIndex The index of the module in the analysis specification +#' @template executionSettings +#' @param ... For future expansion runSchemaCreation <- function(analysisSpecifications, keyringSettings, moduleIndex, executionSettings, ...) { checkmate::assert_multi_class(x = executionSettings, classes = c("ResultsExecutionSettings")) moduleSpecification <- analysisSpecifications$moduleSpecifications[[moduleIndex]] @@ -215,7 +228,7 @@ runSchemaCreation <- function(analysisSpecifications, keyringSettings, moduleInd file = dataModelExportPath, warnOnCaseMismatch = FALSE ) - writeLines('specifications.not.written', doneFIle) + writeLines('specifications.not.written', doneFile) } ParallelLogger::unregisterLogger('DEFAULT_FILE_LOGGER', silent = TRUE) diff --git a/extras/TestModule1-0.0.1/.renvignore b/extras/TestModule1-0.0.1/.renvignore index 199c6e49..04d099ca 100644 --- a/extras/TestModule1-0.0.1/.renvignore +++ b/extras/TestModule1-0.0.1/.renvignore @@ -1,4 +1,3 @@ SettingsFunctions.R extras/ -tests/ diff --git a/extras/TestModule1-0.0.1/renv.lock b/extras/TestModule1-0.0.1/renv.lock index 657bb731..a67cc678 100644 --- a/extras/TestModule1-0.0.1/renv.lock +++ b/extras/TestModule1-0.0.1/renv.lock @@ -48,6 +48,24 @@ ], "Hash": "fafb3d94962b681456ab84eef3cc6c1e" }, + "Eunomia": { + "Package": "Eunomia", + "Version": "1.0.2", + "Source": "GitHub", + "RemoteType": "github", + "RemoteHost": "api.github.com", + "RemoteUsername": "OHDSI", + "RemoteRepo": "Eunomia", + "RemoteRef": "main", + "RemoteSha": "1220fdbe550762ff131f66f05f74f2610a4e85ca", + "Requirements": [ + "DatabaseConnector", + "RSQLite", + "SqlRender", + "readr" + ], + "Hash": "9d4cabd8972e388c95c09524d18a9eab" + }, "ParallelLogger": { "Package": "ParallelLogger", "Version": "3.2.0", @@ -73,6 +91,24 @@ ], "Hash": "470851b6d5d0ac559e9d01bb352b4021" }, + "RSQLite": { + "Package": "RSQLite", + "Version": "2.3.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "DBI", + "R", + "bit64", + "blob", + "cpp11", + "memoise", + "methods", + "pkgconfig", + "plogr" + ], + "Hash": "207c90cd5438a1f596da2cd54c606fee" + }, "Rcpp": { "Package": "Rcpp", "Version": "1.0.10", @@ -147,6 +183,37 @@ ], "Hash": "40415719b5a479b87949f3aa0aee737c" }, + "brio": { + "Package": "brio", + "Version": "1.1.3", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "976cf154dfb043c012d87cddd8bca363" + }, + "cachem": { + "Package": "cachem", + "Version": "1.0.8", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "fastmap", + "rlang" + ], + "Hash": "c35768291560ce302c0a6589f92e837d" + }, + "callr": { + "Package": "callr", + "Version": "3.7.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "R6", + "processx", + "utils" + ], + "Hash": "9b2191ede20fa29828139b9900922e51" + }, "checkmate": { "Package": "checkmate", "Version": "2.2.0", @@ -227,6 +294,35 @@ ], "Hash": "d24305b92db333726aed162a2c23a147" }, + "desc": { + "Package": "desc", + "Version": "1.4.2", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "R6", + "cli", + "rprojroot", + "utils" + ], + "Hash": "6b9602c7ebbe87101a9c8edb6e8b6d21" + }, + "diffobj": { + "Package": "diffobj", + "Version": "0.3.5", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "crayon", + "methods", + "stats", + "tools", + "utils" + ], + "Hash": "bcaa8b95f8d7d01a5dedfd959ce88ab8" + }, "digest": { "Package": "digest", "Version": "0.6.31", @@ -261,6 +357,28 @@ ], "Hash": "dea6970ff715ca541c387de363ff405e" }, + "ellipsis": { + "Package": "ellipsis", + "Version": "0.3.2", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "rlang" + ], + "Hash": "bb0eec2fe32e88d9e2836c2f73ea2077" + }, + "evaluate": { + "Package": "evaluate", + "Version": "0.21", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "methods" + ], + "Hash": "d59f3b464e8da1aef82dc04b588b8dfb" + }, "fansi": { "Package": "fansi", "Version": "1.0.4", @@ -273,6 +391,24 @@ ], "Hash": "1d9e7ad3c8312a192dea7d3db0274fde" }, + "fastmap": { + "Package": "fastmap", + "Version": "1.1.1", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "f7736a18de97dea803bde0a2daaafb27" + }, + "fs": { + "Package": "fs", + "Version": "1.6.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "methods" + ], + "Hash": "47b5f30c720c23999b913a1a635cf0bb" + }, "generics": { "Package": "generics", "Version": "0.1.3", @@ -342,6 +478,17 @@ ], "Hash": "7ce2733a9826b3aeb1775d56fd305472" }, + "memoise": { + "Package": "memoise", + "Version": "2.0.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "cachem", + "rlang" + ], + "Hash": "e2817ccf4a065c5d9d7f2cfbe7c1d78c" + }, "pillar": { "Package": "pillar", "Version": "1.9.0", @@ -369,6 +516,40 @@ ], "Hash": "01f28d4278f15c76cddbea05899c5d6f" }, + "pkgload": { + "Package": "pkgload", + "Version": "1.3.2.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "cli", + "crayon", + "desc", + "fs", + "glue", + "methods", + "rlang", + "rprojroot", + "utils", + "withr" + ], + "Hash": "a7f498a1b2a4a6816148e498509f6e1d" + }, + "plogr": { + "Package": "plogr", + "Version": "0.2.0", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "09eb987710984fc2905c7129c7d85e65" + }, + "praise": { + "Package": "praise", + "Version": "1.0.0", + "Source": "Repository", + "Repository": "RSPM", + "Hash": "a555924add98c99d2f411e37e7d25e9f" + }, "prettyunits": { "Package": "prettyunits", "Version": "1.1.1", @@ -376,6 +557,19 @@ "Repository": "CRAN", "Hash": "95ef9167b75dde9d2ccc3c7528393e7e" }, + "processx": { + "Package": "processx", + "Version": "3.8.2", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "R6", + "ps", + "utils" + ], + "Hash": "3efbd8ac1be0296a46c55387aeace0f3" + }, "progress": { "Package": "progress", "Version": "1.2.2", @@ -389,6 +583,17 @@ ], "Hash": "14dc9f7a3c91ebb14ec5bb9208a07061" }, + "ps": { + "Package": "ps", + "Version": "1.7.5", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "utils" + ], + "Hash": "709d852d33178db54b17c722e5b1e594" + }, "purrr": { "Package": "purrr", "Version": "1.0.1", @@ -438,6 +643,16 @@ ], "Hash": "b5047343b3825f37ad9d3b5d89aa1078" }, + "rematch2": { + "Package": "rematch2", + "Version": "2.1.2", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "tibble" + ], + "Hash": "76c9e04c712a05848ae7a23d2f170a40" + }, "renv": { "Package": "renv", "Version": "1.0.2", @@ -459,6 +674,16 @@ ], "Hash": "dc079ccd156cde8647360f473c1fa718" }, + "rprojroot": { + "Package": "rprojroot", + "Version": "2.0.3", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R" + ], + "Hash": "1de7ab598047a87bba48434ba35d497d" + }, "snow": { "Package": "snow", "Version": "0.4-4", @@ -500,6 +725,36 @@ ], "Hash": "671a4d384ae9d32fc47a14e98bfa3dc8" }, + "testthat": { + "Package": "testthat", + "Version": "3.1.10", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "R", + "R6", + "brio", + "callr", + "cli", + "desc", + "digest", + "ellipsis", + "evaluate", + "jsonlite", + "lifecycle", + "magrittr", + "methods", + "pkgload", + "praise", + "processx", + "ps", + "rlang", + "utils", + "waldo", + "withr" + ], + "Hash": "6f403dc49295610a3a67ea1a9ca64346" + }, "tibble": { "Package": "tibble", "Version": "3.2.1", @@ -642,6 +897,23 @@ ], "Hash": "7015a74373b83ffaef64023f4a0f5033" }, + "waldo": { + "Package": "waldo", + "Version": "0.5.1", + "Source": "Repository", + "Repository": "RSPM", + "Requirements": [ + "cli", + "diffobj", + "fansi", + "glue", + "methods", + "rematch2", + "rlang", + "tibble" + ], + "Hash": "2c993415154cdb94649d99ae138ff5e5" + }, "withr": { "Package": "withr", "Version": "2.5.0", diff --git a/inst/doc/CreatingAnalysisSpecification.pdf b/inst/doc/CreatingAnalysisSpecification.pdf deleted file mode 100644 index a4ba0a45..00000000 Binary files a/inst/doc/CreatingAnalysisSpecification.pdf and /dev/null differ diff --git a/inst/doc/CreatingModules.pdf b/inst/doc/CreatingModules.pdf deleted file mode 100644 index 5bc4f0bc..00000000 Binary files a/inst/doc/CreatingModules.pdf and /dev/null differ diff --git a/inst/doc/ExecuteStrategus.pdf b/inst/doc/ExecuteStrategus.pdf deleted file mode 100644 index ffa0e682..00000000 Binary files a/inst/doc/ExecuteStrategus.pdf and /dev/null differ diff --git a/inst/doc/IntroductionToStrategus.pdf b/inst/doc/IntroductionToStrategus.pdf deleted file mode 100644 index 0496eb08..00000000 Binary files a/inst/doc/IntroductionToStrategus.pdf and /dev/null differ diff --git a/inst/testdata/TestModule1_0.0.1.zip b/inst/testdata/TestModule1_0.0.1.zip index 843827f1..c0f77ea2 100644 Binary files a/inst/testdata/TestModule1_0.0.1.zip and b/inst/testdata/TestModule1_0.0.1.zip differ diff --git a/man-roxygen/executionSettings.R b/man-roxygen/executionSettings.R new file mode 100644 index 00000000..a80e89b8 --- /dev/null +++ b/man-roxygen/executionSettings.R @@ -0,0 +1,2 @@ +#' @param executionSettings An object of type `ExecutionSettings` as created +#' by [createCdmExecutionSettings()] or [createResultsExecutionSettings()]. diff --git a/man/runSchemaCreation.Rd b/man/runSchemaCreation.Rd index c4a631df..821bab19 100644 --- a/man/runSchemaCreation.Rd +++ b/man/runSchemaCreation.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/ResultModelCreation.R \name{runSchemaCreation} \alias{runSchemaCreation} -\title{Results upload callbacks for inserting results in to a database} +\title{Create module(s) result data model} \usage{ runSchemaCreation( analysisSpecifications, @@ -12,6 +12,24 @@ runSchemaCreation( ... ) } +\arguments{ +\item{analysisSpecifications}{An object of type \code{AnalysisSpecifications} as created +by \code{\link[=createEmptyAnalysisSpecificiations]{createEmptyAnalysisSpecificiations()}}.} + +\item{keyringSettings}{The keyringSettings from the executionSettings context} + +\item{moduleIndex}{The index of the module in the analysis specification} + +\item{executionSettings}{An object of type \code{ExecutionSettings} as created +by \code{\link[=createCdmExecutionSettings]{createCdmExecutionSettings()}} or \code{\link[=createResultsExecutionSettings]{createResultsExecutionSettings()}}.} + +\item{...}{For future expansion} +} \description{ -Results upload callbacks for inserting results in to a database +This function will create the results data model for the modules in the +\code{analysisSpecifications}. A module can implement its own results data model +creation function by implementing the function \code{createDataModelSchema} in +its Main.R. The default behavior is to use the \code{ResultsModelManager} to create +the results data model based on the \code{resultsDataModelSpecification.csv} in the +module's results folder. } diff --git a/tests/testthat/setup.R b/tests/testthat/setup.R index 72fb112b..7fdfa822 100644 --- a/tests/testthat/setup.R +++ b/tests/testthat/setup.R @@ -34,7 +34,7 @@ if (dir.exists(Sys.getenv("DATABASECONNECTOR_JAR_FOLDER"))) { tableSuffix <- paste0(substr(.Platform$OS.type, 1, 3), format(Sys.time(), "%y%m%d%H%M%S"), sample(1:100, 1)) tableSuffix <- abs(digest::digest2int(tableSuffix)) -tempDir <- tempfile() #"C:/temp" +tempDir <- tempfile() tempDir <- gsub("\\\\", "/", tempDir) # Correct windows path renvCachePath <- file.path(tempDir, "strategus/renv") moduleFolder <- file.path(tempDir, "strategus/modules")