Skip to content

Commit

Permalink
Move to internal unit test package and try to remedy some R CMD check…
Browse files Browse the repository at this point in the history
… warnings
  • Loading branch information
anthonysena committed Aug 22, 2023
1 parent 4fdc96a commit 81d7745
Show file tree
Hide file tree
Showing 12 changed files with 334 additions and 34 deletions.
38 changes: 17 additions & 21 deletions R/Execution.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand All @@ -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,
Expand Down
31 changes: 22 additions & 9 deletions R/ResultModelCreation.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#' If recreate is set to TRUE all existing data will be removed, otherwise
#'
#' @inheritParams execute
#'
#' @export
createResultDataModels <- function(analysisSpecifications,
executionSettings,
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -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]]
Expand Down Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion extras/TestModule1-0.0.1/.renvignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
SettingsFunctions.R

extras/
tests/
Loading

0 comments on commit 81d7745

Please sign in to comment.