Skip to content

Commit

Permalink
reverted call to closure
Browse files Browse the repository at this point in the history
  • Loading branch information
azimov committed Jan 6, 2025
1 parent 8b1c39a commit 6ab78fb
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
10 changes: 7 additions & 3 deletions R/RunAnalyses.R
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ runSccAnalyses <- function(connectionDetails,
computeThreads = 1) {

# Get negative controls

checkmate::assertChoice(controlType, c("outcome", "exposure"))
negatives <- list()
for (exposureOutcome in exposureOutcomeList) {
Expand Down Expand Up @@ -123,13 +122,18 @@ runSccAnalyses <- function(connectionDetails,
resultExportPath = file.path(outputFolder, paste0("A_", refRow$analysisId)),
computeThreads = computeThreads)
args <- append(args, getrunSelfControlledCohortArgs)
executionArgList[[length(executionArgList) + 1]] <- args
executionArgList[[length(executionArgList) + 1]] <- list(args = args)
}

exececuteScc <- function(params) {
sccResults <- do.call("runSelfControlledCohort", params$args)
}

if (length(executionArgList) != 0) {
cluster <- ParallelLogger::makeCluster(analysisThreads)
ParallelLogger::clusterRequire(cluster, "SelfControlledCohort")
dummy <- ParallelLogger::clusterApply(cluster, executionArgList, runSelfControlledCohort)

dummy <- ParallelLogger::clusterApply(cluster, executionArgList, exececuteScc)
ParallelLogger::stopCluster(cluster)
}

Expand Down
20 changes: 12 additions & 8 deletions R/SelfControlledCohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ computeIrrs <- function(estimates) {
}



batchComputeEstimates <- function(connection,
computeThreads,
resultsTable,
Expand All @@ -79,12 +78,12 @@ batchComputeEstimates <- function(connection,
rows <- split(rows, rep_len(1:batches, nrow(rows)))
rows <- ParallelLogger::clusterApply(cluster, rows, computeIrrs, progressBar = FALSE)
rows <- do.call(rbind, rows)
}

if (position == 1) {
andromeda$estimates <- rows
} else {
Andromeda::appendToTable(andromeda$estimates, rows)
}
if (position == 1) {
andromeda$estimates <- rows
} else {
Andromeda::appendToTable(andromeda$estimates, rows)
}

return(rows)
Expand All @@ -100,6 +99,11 @@ batchComputeEstimates <- function(connection,
transformFunctionArgs = args,
append = FALSE)

if (is.null(andromeda$estimates)) {
ParallelLogger::logInfo("No effect estimates produced")
return(NULL)
}

if (length(negativeControlPairs) > 0) {
ncPairsDf <- do.call(rbind, lapply(negativeControlPairs, function(eo) {
data.frame(targetCohortId = eo[[1]], outcomeCohortId = eo[[2]])
Expand Down Expand Up @@ -131,7 +135,7 @@ batchComputeEstimates <- function(connection,
ncPairsDf |>
dplyr::group_by(.data$outcomeCohortId) |>
dplyr::group_map(function(data, outcomeCohortId) {

browser()
estimates <- andromeda$estimates |>
dplyr::filter(.data$outcomeCohortId == outcomeCohortId)

Expand Down Expand Up @@ -472,7 +476,7 @@ runSelfControlledCohort <- function(connectionDetails = NULL,
DatabaseConnector::executeSql(connection, sql)

resultExportManager$writeManifest(packageName = utils::packageName(),
packageVersion = packageVersion(utils::packageName()))
packageVersion = packageVersion(utils::packageName()))

delta <- Sys.time() - start
ParallelLogger::logInfo(paste("Performing SCC analysis took", signif(delta, 3), attr(delta, "units")))
Expand Down

0 comments on commit 6ab78fb

Please sign in to comment.