Skip to content

Commit

Permalink
Add cache for validate external (#455)
Browse files Browse the repository at this point in the history
closes #455
  • Loading branch information
egillax authored May 31, 2024
1 parent 9e89253 commit 396fa4b
Showing 1 changed file with 25 additions and 8 deletions.
33 changes: 25 additions & 8 deletions R/ExternalValidatePlp.R
Original file line number Diff line number Diff line change
Expand Up @@ -473,6 +473,11 @@ validateExternal <- function(validationDesignList,
init = TRUE)) {
stop("covariateSettings are not the same across models which is not supported yet")
}
plpDataName <-
paste0("targetId_", design$targetId, "_L", "1") # Is the 1 for how many targetIds in file ?
plpDataLocation <-
file.path(outputFolder, databaseName, plpDataName)
if (!dir.exists(plpDataLocation)) {
plpData <- tryCatch({
do.call(
getPlpData,
Expand All @@ -491,15 +496,15 @@ validateExternal <- function(validationDesignList,
ParallelLogger::logInfo("Couldn't extract plpData for the given design and database, proceding to the next one.")
next
}
plpDataName <-
paste0("targetId_", design$targetId, "_L", "1") # Is the 1 for how many targetIds in file ?
plpDataLocation <-
file.path(outputFolder, databaseName, plpDataName)
if (!dir.exists(file.path(outputFolder, databaseName))) {
dir.create(file.path(outputFolder, databaseName), recursive = TRUE)
}
savePlpData(plpData, file = plpDataLocation)

} else {
ParallelLogger::logInfo(paste0("Data already extracted for ",
plpDataName, ": Loading from disk"))
plpData <- loadPlpData(plpDataLocation)
}
# create study population
population <- tryCatch({
do.call(
Expand All @@ -515,9 +520,18 @@ validateExternal <- function(validationDesignList,
ParallelLogger::logError(e)
return(NULL)
})

results <- lapply(design$plpModelList, function(model) {
analysisName <- paste0("Analysis_", analysisInfo[databaseName])
analysisDone <- file.exists(
file.path(
outputFolder,
databaseName,
analysisName,
'validationResult',
'runPlp.rds'
)
)
if (!analysisDone) {
validateModel(
plpModel = model,
plpData = plpData,
Expand All @@ -526,8 +540,11 @@ validateExternal <- function(validationDesignList,
runCovariateSummary = design$runCovariateSummary,
outputFolder = outputFolder,
databaseName = databaseName,
analysisName = analysisName
)
analysisName = analysisName)
} else {
ParallelLogger::logInfo(paste0("Analysis ", analysisName, " already done",
", Proceeding to the next one."))
}
analysisInfo[[databaseName]] <<- analysisInfo[[databaseName]] + 1
})
}
Expand Down

0 comments on commit 396fa4b

Please sign in to comment.