Skip to content

Commit

Permalink
Release v0.2.0
Browse files Browse the repository at this point in the history
Release v0.2.0
  • Loading branch information
anthonysena authored Jan 26, 2024
2 parents 00d0c00 + bda6bef commit 0e733ec
Show file tree
Hide file tree
Showing 89 changed files with 6,473 additions and 1,462 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/R_CMD_check_Hades.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
matrix:
config:
- {os: windows-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
- {os: macOS-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
#- {os: macOS-latest, r: '4.2.3', rtools: '42', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-20.04, r: '4.2.3', rtools: '42', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: windows-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
#- {os: macOS-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
- {os: macOS-latest, r: 'release', rtools: '', rspm: "https://cloud.r-project.org"}
- {os: ubuntu-20.04, r: 'release', rtools: '', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}

env:
Expand Down
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: Strategus
Type: Package
Title: Coordinating and Executing Analytics Using HADES Modules
Version: 0.1.0
Date: 2023-10-04
Version: 0.2.0
Date: 2023-01-26
Authors@R: c(
person("Martijn", "Schuemie", email = "[email protected]", role = c("aut")),
person("Anthony", "Sena", email = "[email protected]", role = c("aut", "cre")),
Expand Down Expand Up @@ -32,7 +32,8 @@ Imports:
methods,
tibble,
ResultModelManager (>= 0.3.0),
SqlRender (>= 1.11.0)
SqlRender (>= 1.11.0),
semver
Suggests:
testthat (>= 3.0.0),
fs,
Expand All @@ -46,7 +47,7 @@ Remotes:
ohdsi/Eunomia
VignetteBuilder: knitr
NeedsCompilation: no
RoxygenNote: 7.2.3
RoxygenNote: 7.3.1
Roxygen: list(markdown = TRUE)
Encoding: UTF-8
Config/testthat/edition: 3
4 changes: 4 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

export(addModuleSpecifications)
export(addSharedResources)
export(compareLockFiles)
export(createCdmExecutionSettings)
export(createEmptyAnalysisSpecificiations)
export(createResultDataModels)
Expand All @@ -11,7 +12,10 @@ export(execute)
export(getModuleList)
export(retrieveConnectionDetails)
export(storeConnectionDetails)
export(syncLockFile)
export(unlockKeyring)
export(validateLockFile)
export(verifyModuleInstallation)
import(CohortGenerator)
import(DatabaseConnector)
import(dplyr)
Expand Down
11 changes: 11 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,14 @@
Strategus 0.2.0
===============
- Add functions for developers to help with renv.lock file validation (#69)
- Use renv project profiles for modules (#94)
- Convert relative paths to absolute path before passing to a module (#99)
- Address missing package dependencies in modules (#99)
- Throw informative error message when connection detail reference not set in keyring (#100)
- Validate execution settings (#101)
- Pass temp emulation schema properly (#76)
- Remove local library package dependencies (#96)

Strategus 0.1.0
===============

Expand Down
2 changes: 1 addition & 1 deletion R/DatabaseMetaData.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Observational Health Data Sciences and Informatics
# Copyright 2024 Observational Health Data Sciences and Informatics
#
# This file is part of Strategus
#
Expand Down
61 changes: 52 additions & 9 deletions R/Execution.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Observational Health Data Sciences and Informatics
# Copyright 2024 Observational Health Data Sciences and Informatics
#
# This file is part of Strategus
#
Expand Down Expand Up @@ -48,9 +48,10 @@ 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
# Validate the execution settings
if (is(executionSettings, "CdmExecutionSettings")) {
# Assert that the temp emulation schema is set if required for the dbms
# specified by the executionSettings
connectionDetails <- retrieveConnectionDetails(
connectionDetailsReference = executionSettings$connectionDetailsReference,
keyringName = keyringName
Expand All @@ -59,8 +60,48 @@ execute <- function(analysisSpecifications,
dbms = connectionDetails$dbms,
tempEmulationSchema = executionSettings$tempEmulationSchema
)

# Validate that the table names specified in the execution settings
# do not violate the maximum table length. To do this we will render
# a query using the execution settings so that SqlRender can provide
# the appropriate warning. Only stop execution if we are running on
# Oracle; otherwise it is unclear if the table name length will have
# an impact
cohortTableChecks <- lapply(
X = executionSettings$cohortTableNames,
FUN = function(tableName) {
sql <- SqlRender::render(
sql = "CREATE TABLE @table;",
table = tableName
)
tryCatch(
{
SqlRender::translate(
sql = sql,
targetDialect = connectionDetails$dbms
)
return(TRUE)
},
warning = function(w) {
warning(w)
return(FALSE)
}
)
}
)

# Since the warning is thrown for all dbms systems, only stop if
# we are executing on Oracle
if (tolower(connectionDetails$dbms) == "oracle" && !all(unlist(cohortTableChecks))) {
stop("Your cohort table names are too long for Oracle. Please update your executionSettings to use shorter cohort table names and try again.")
}
}

# Validate the modules
modules <- ensureAllModulesInstantiated(analysisSpecifications)
if (isFALSE(modules$allModulesInstalled)) {
stop("Stopping execution due to module issues")
}

if (is.null(executionScriptFolder)) {
executionScriptFolder <- tempfile("strategusTempSettings")
Expand All @@ -72,14 +113,16 @@ execute <- function(analysisSpecifications,
}
dir.create(executionScriptFolder, recursive = TRUE)
}
# Normalize path to convert from relative to absolute path
executionScriptFolder <- normalizePath(executionScriptFolder, mustWork = F)

if (is(executionSettings, "CdmExecutionSettings")) {
executionSettings$databaseId <- createDatabaseMetaData(
executionSettings = executionSettings,
keyringName = keyringName
)
}
dependencies <- extractDependencies(modules)
dependencies <- extractDependencies(modules$modules)


fileName <- generateTargetsScript(
Expand Down Expand Up @@ -154,11 +197,11 @@ generateTargetsScript <- function(analysisSpecifications, executionSettings, dep
)

# Store settings objects in the temp folder so they are available in targets
analysisSpecificationsFileName <- gsub("\\\\", "/", file.path(executionScriptFolder, "analysisSpecifications.rds"))
analysisSpecificationsFileName <- .formatAndNormalizeFilePathForScript(file.path(executionScriptFolder, "analysisSpecifications.rds"))
saveRDS(analysisSpecifications, analysisSpecificationsFileName)
executionSettingsFileName <- gsub("\\\\", "/", file.path(executionScriptFolder, "executionSettings.rds"))
executionSettingsFileName <- .formatAndNormalizeFilePathForScript(file.path(executionScriptFolder, "executionSettings.rds"))
saveRDS(executionSettings, executionSettingsFileName)
keyringSettingsFileName <- gsub("\\\\", "/", file.path(executionScriptFolder, "keyringSettings.rds"))
keyringSettingsFileName <- .formatAndNormalizeFilePathForScript(file.path(executionScriptFolder, "keyringSettings.rds"))
saveRDS(list(keyringName = keyringName), keyringSettingsFileName)

# Generate target names by module type
Expand All @@ -172,10 +215,10 @@ generateTargetsScript <- function(analysisSpecifications, executionSettings, dep
)
}
moduleToTargetNames <- bind_rows(moduleToTargetNames)
moduleToTargetNamesFileName <- gsub("\\\\", "/", file.path(executionScriptFolder, "moduleTargetNames.rds"))
moduleToTargetNamesFileName <- .formatAndNormalizeFilePathForScript(file.path(executionScriptFolder, "moduleTargetNames.rds"))
saveRDS(moduleToTargetNames, moduleToTargetNamesFileName)

dependenciesFileName <- gsub("\\\\", "/", file.path(executionScriptFolder, "dependencies.rds"))
dependenciesFileName <- .formatAndNormalizeFilePathForScript(file.path(executionScriptFolder, "dependencies.rds"))
saveRDS(dependencies, dependenciesFileName)

execResultsUpload <- all(c(
Expand Down
28 changes: 13 additions & 15 deletions R/ModuleEnv.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2023 Observational Health Data Sciences and Informatics
# Copyright 2024 Observational Health Data Sciences and Informatics
#
# This file is part of Strategus
#
Expand Down Expand Up @@ -47,16 +47,13 @@
#' @param 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!
#' @param tempScriptFile tempFile to write script to
#' @param useLocalStrategusLibrary Use the locally installed Strategus library? TRUE will use the Strategus
#' installation from the calling R process.
#' @param job run as rstudio job
#' @param processName String name for process
#' @returns NULL invisibly
withModuleRenv <- function(code,
moduleFolder,
injectVars = list(),
tempScriptFile = tempfile(fileext = ".R"),
useLocalStrategusLibrary = TRUE,
job = FALSE,
processName = paste(moduleFolder, "_renv_run")) {
# convert human readable code to a string for writing
Expand All @@ -81,19 +78,16 @@ withModuleRenv <- function(code,
}
}

# Enforce attachment of Strategus from calling process - note one inside the renv
if (useLocalStrategusLibrary) {
script <- c(.getLocalLibraryScipt("Strategus"), script)
# Adding Strategus dependencies to the script
script <- c(.getLocalLibraryScipt("ParallelLogger"), script)
script <- c(.getLocalLibraryScipt("CohortGenerator"), script)
script <- c(.getLocalLibraryScipt("DatabaseConnector"), script)
script <- c(.getLocalLibraryScipt("keyring"), script)
script <- c(.getLocalLibraryScipt("openssl"), script)
script <- c(.getLocalLibraryScipt("dplyr"), script)
script <- c(.getLocalLibraryScipt("R6"), script)
# Turning off verbose output to hide renv output
# unless the user has set this option to TRUE.
if (!getOption(x = "renv.verbose", default = FALSE)) {
options(renv.verbose = FALSE)
}

# Import the Strategus functions we need to use in the module scripts
script <- c("retrieveConnectionDetails <- ", base::deparse(Strategus::retrieveConnectionDetails), script)
script <- c("unlockKeyring <- ", base::deparse(Strategus::unlockKeyring), script)

# Write file and execute script inside an renv
fileConn <- file(tempScriptFile)
writeLines(script, fileConn)
Expand Down Expand Up @@ -123,3 +117,7 @@ withModuleRenv <- function(code,
paste0("# option = ", optionName, " - could not be passed to this file, likely because it is a function.")
}
}

.formatAndNormalizeFilePathForScript <- function(filePath) {
return(gsub("\\\\", "/", normalizePath(path = filePath, mustWork = F)))
}
Loading

0 comments on commit 0e733ec

Please sign in to comment.