diff --git a/DESCRIPTION b/DESCRIPTION index ec8a067..8f7a543 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: Characterization Type: Package Title: Characterizations of Cohorts -Version: 0.1.4 -Date: 2024-02-26 +Version: 0.1.5 +Date: 2024-04-03 Authors@R: c( person("Jenna", "Reps", , "reps@ohdsi.org", role = c("aut", "cre")), person("Patrick", "Ryan", , "ryan@ohdsi.org", role = c("aut")) @@ -42,6 +42,6 @@ Remotes: ohdsi/ShinyAppBuilder, ohdsi/DatabaseConnector NeedsCompilation: no -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 Encoding: UTF-8 VignetteBuilder: knitr diff --git a/NEWS.md b/NEWS.md index dc879bf..acf123e 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,7 @@ +Characterization 0.1.5 +====================== +Changed export to csv approach to use batch export from SQLite (#41) + Characterization 0.1.4 ====================== Added extra error logging @@ -21,7 +25,7 @@ Fixing bug where cohort_counts were not being saved in the database Characterization 0.1.0 ====================== -- added support to enable target cohorts with multiple cohort entries for the aggregate covariate analysis by restructing to first cohort entry and ensuring the subject has a user specified minPriorObservation days observation in the database at first entry and also perform analysis on first outcomes and any outcome that is recorded during TAR. +- added support to enable target cohorts with multiple cohort entries for the aggregate covariate analysis by restricting to first cohort entry and ensuring the subject has a user specified minPriorObservation days observation in the database at first entry and also perform analysis on first outcomes and any outcome that is recorded during TAR. - added shiny app diff --git a/R/AggregateCovariates.R b/R/AggregateCovariates.R index 02e17ac..bad74ec 100644 --- a/R/AggregateCovariates.R +++ b/R/AggregateCovariates.R @@ -1,4 +1,4 @@ -# Copyright 2022 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of Characterization # @@ -27,27 +27,25 @@ #' #' @export createAggregateCovariateSettings <- function( - targetIds, - outcomeIds, - minPriorObservation = 0, - riskWindowStart = 1, - startAnchor = 'cohort start', - riskWindowEnd = 365, - endAnchor = 'cohort start', - covariateSettings -){ - + targetIds, + outcomeIds, + minPriorObservation = 0, + riskWindowStart = 1, + startAnchor = "cohort start", + riskWindowEnd = 365, + endAnchor = "cohort start", + covariateSettings) { errorMessages <- checkmate::makeAssertCollection() # check targetIds is a vector of int/double .checkCohortIds( cohortIds = targetIds, - type = 'target', + type = "target", errorMessages = errorMessages ) # check outcomeIds is a vector of int/double .checkCohortIds( cohortIds = outcomeIds, - type = 'outcome', + type = "outcome", errorMessages = errorMessages ) @@ -81,12 +79,12 @@ createAggregateCovariateSettings <- function( minPriorObservation = minPriorObservation, riskWindowStart = riskWindowStart, startAnchor = startAnchor, - riskWindowEnd = riskWindowEnd , + riskWindowEnd = riskWindowEnd, endAnchor = endAnchor, covariateSettings = covariateSettings ) - class(result) <- 'aggregateCovariateSettings' + class(result) <- "aggregateCovariateSettings" return(result) } @@ -106,19 +104,17 @@ createAggregateCovariateSettings <- function( #' #' @export computeAggregateCovariateAnalyses <- function( - connectionDetails = NULL, - cdmDatabaseSchema, - cdmVersion = 5, - targetDatabaseSchema, - targetTable, - outcomeDatabaseSchema = targetDatabaseSchema, # remove - outcomeTable = targetTable, # remove - tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), - aggregateCovariateSettings, - databaseId = 'database 1', - runId = 1 -) { - + connectionDetails = NULL, + cdmDatabaseSchema, + cdmVersion = 5, + targetDatabaseSchema, + targetTable, + outcomeDatabaseSchema = targetDatabaseSchema, # remove + outcomeTable = targetTable, # remove + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), + aggregateCovariateSettings, + databaseId = "database 1", + runId = 1) { # check inputs start <- Sys.time() @@ -128,7 +124,7 @@ computeAggregateCovariateAnalyses <- function( ) on.exit( DatabaseConnector::disconnect(connection) - ) + ) # select T, O, create TnO, TnOc, Onprior T # into temp table #agg_cohorts @@ -145,11 +141,11 @@ computeAggregateCovariateAnalyses <- function( ) ## get counts - sql <- 'select cohort_definition_id, count(*) row_count, count(distinct subject_id) person_count from #agg_cohorts group by cohort_definition_id;' + sql <- "select cohort_definition_id, count(*) row_count, count(distinct subject_id) person_count from #agg_cohorts group by cohort_definition_id;" sql <- SqlRender::translate( sql = sql, targetDialect = connectionDetails$dbms - ) + ) counts <- DatabaseConnector::querySql( connection = connection, sql = sql, @@ -162,7 +158,7 @@ computeAggregateCovariateAnalyses <- function( connection = connection, oracleTempSchema = tempEmulationSchema, cdmDatabaseSchema = cdmDatabaseSchema, - cohortTable = '#agg_cohorts', + cohortTable = "#agg_cohorts", cohortTableIsTemp = T, cohortId = -1, covariateSettings = aggregateCovariateSettings$covariateSettings, @@ -176,7 +172,7 @@ computeAggregateCovariateAnalyses <- function( # could add settings table with this and just have setting id # as single extra column? - for(tableName in names(result)){ + for (tableName in names(result)) { result[[tableName]] <- result[[tableName]] %>% dplyr::mutate( runId = !!runId, @@ -185,16 +181,16 @@ computeAggregateCovariateAnalyses <- function( dplyr::relocate( "databaseId", "runId" - ) + ) } -# cohort details: + # cohort details: result$cohortDetails <- DatabaseConnector::querySql( connection = connection, sql = SqlRender::translate( - sql = " select * from #cohort_details;", - targetDialect = connectionDetails$dbms + sql = " select * from #cohort_details;", + targetDialect = connectionDetails$dbms ), snakeCaseToCamelCase = T ) %>% @@ -218,14 +214,14 @@ computeAggregateCovariateAnalyses <- function( ) result$settings <- data.frame( - runId = runId, - databaseId = databaseId, - covariateSettingJson = covariateSettingsJson, - riskWindowStart = aggregateCovariateSettings$riskWindowStart, - startAnchor = aggregateCovariateSettings$startAnchor, - riskWindowEnd = aggregateCovariateSettings$riskWindowEnd , - endAnchor = aggregateCovariateSettings$endAnchor - ) + runId = runId, + databaseId = databaseId, + covariateSettingJson = covariateSettingsJson, + riskWindowStart = aggregateCovariateSettings$riskWindowStart, + startAnchor = aggregateCovariateSettings$startAnchor, + riskWindowEnd = aggregateCovariateSettings$riskWindowEnd, + endAnchor = aggregateCovariateSettings$endAnchor + ) sql <- SqlRender::loadRenderTranslateSql( sqlFilename = "DropAggregateCovariate.sql", @@ -245,17 +241,15 @@ computeAggregateCovariateAnalyses <- function( createCohortsOfInterest <- function( - connection, - cdmDatabaseSchema, - dbms, - aggregateCovariateSettings, - targetDatabaseSchema, - targetTable, - outcomeDatabaseSchema, - outcomeTable, - tempEmulationSchema -){ - + connection, + cdmDatabaseSchema, + dbms, + aggregateCovariateSettings, + targetDatabaseSchema, + targetTable, + outcomeDatabaseSchema, + outcomeTable, + tempEmulationSchema) { sql <- SqlRender::loadRenderTranslateSql( sqlFilename = "createTargetOutcomeCombinations.sql", packageName = "Characterization", @@ -266,21 +260,21 @@ createCohortsOfInterest <- function( target_table = targetTable, outcome_database_schema = outcomeDatabaseSchema, outcome_table = outcomeTable, - target_ids = paste(aggregateCovariateSettings$targetIds, collapse = ',', sep = ','), - outcome_ids = paste(aggregateCovariateSettings$outcomeIds, collapse = ',', sep = ','), + target_ids = paste(aggregateCovariateSettings$targetIds, collapse = ",", sep = ","), + outcome_ids = paste(aggregateCovariateSettings$outcomeIds, collapse = ",", sep = ","), min_prior_observation = aggregateCovariateSettings$minPriorObservation, tar_start = aggregateCovariateSettings$riskWindowStart, tar_start_anchor = ifelse( - aggregateCovariateSettings$startAnchor == 'cohort start', - 'cohort_start_date', - 'cohort_end_date' - ), + aggregateCovariateSettings$startAnchor == "cohort start", + "cohort_start_date", + "cohort_end_date" + ), tar_end = aggregateCovariateSettings$riskWindowEnd, tar_end_anchor = ifelse( - aggregateCovariateSettings$endAnchor == 'cohort start', - 'cohort_start_date', - 'cohort_end_date' - ) + aggregateCovariateSettings$endAnchor == "cohort start", + "cohort_start_date", + "cohort_end_date" + ) ) DatabaseConnector::executeSql( @@ -289,5 +283,4 @@ createCohortsOfInterest <- function( progressBar = FALSE, reportOverallTime = FALSE ) - } diff --git a/R/Characterization.R b/R/Characterization.R index 3885f20..9c47bbb 100644 --- a/R/Characterization.R +++ b/R/Characterization.R @@ -1,4 +1,4 @@ -# Copyright 2022 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of Characterization # diff --git a/R/Database.R b/R/Database.R index 592ec33..249d761 100644 --- a/R/Database.R +++ b/R/Database.R @@ -1,6 +1,6 @@ # @file Database.R # -# Copyright 2022 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of Characterization # @@ -30,15 +30,13 @@ #' #' @export createSqliteDatabase <- function( - sqliteLocation = tempdir() -){ - + sqliteLocation = tempdir()) { sqliteLocation <- file.path( sqliteLocation, - 'sqliteCharacterization' + "sqliteCharacterization" ) - if(!dir.exists(sqliteLocation )){ + if (!dir.exists(sqliteLocation)) { dir.create( path = sqliteLocation, recursive = T @@ -46,8 +44,8 @@ createSqliteDatabase <- function( } connectionDetails <- DatabaseConnector::createConnectionDetails( - dbms = 'sqlite', - server = file.path(sqliteLocation, 'sqlite.sqlite') + dbms = "sqlite", + server = file.path(sqliteLocation, "sqlite.sqlite") ) connection <- DatabaseConnector::connect( connectionDetails = connectionDetails @@ -64,10 +62,9 @@ insertAndromedaToDatabase <- function( andromedaObject, tempEmulationSchema, bulkLoad = T, - tablePrefix = 'c_', + tablePrefix = "c_", minCellCount = 0, - minCellCountColumns = list() -){ + minCellCountColumns = list()) { errorMessages <- checkmate::makeAssertCollection() .checkTablePrefix( tablePrefix = tablePrefix, @@ -75,12 +72,11 @@ insertAndromedaToDatabase <- function( ) checkmate::reportAssertions(errorMessages) - message('Inserting Andromeda table into database table ', tablePrefix, tableName) + message("Inserting Andromeda table into database table ", tablePrefix, tableName) Andromeda::batchApply( tbl = andromedaObject, - fun = function(x){ - + fun = function(x) { data <- as.data.frame(x %>% dplyr::collect()) # apply minCellCount data <- removeMinCell( data = data, @@ -91,7 +87,7 @@ insertAndromedaToDatabase <- function( DatabaseConnector::insertTable( connection = connection, databaseSchema = databaseSchema, - tableName = paste0(tablePrefix,tableName), + tableName = paste0(tablePrefix, tableName), data = data, dropTableIfExists = F, createTable = F, @@ -108,22 +104,21 @@ insertAndromedaToDatabase <- function( removeMinCell <- function( data, minCellCount = 0, - minCellCountColumns = list() -){ - for(columns in minCellCountColumns){ + minCellCountColumns = list()) { + for (columns in minCellCountColumns) { ind <- apply( - X = data[,columns, drop = FALSE], + X = data[, columns, drop = FALSE], MARGIN = 1, - FUN = function(x) sum(x < minCellCount)>0 + FUN = function(x) sum(x < minCellCount) > 0 ) - if(sum(ind) > 0 ){ + if (sum(ind) > 0) { ParallelLogger::logInfo( paste0( - 'Removing values less than ', + "Removing values less than ", minCellCount, - ' from ', - paste(columns, collapse = ' and ') + " from ", + paste(columns, collapse = " and ") ) ) data[ind, columns] <- -1 @@ -158,12 +153,11 @@ removeMinCell <- function( createCharacterizationTables <- function( conn, resultSchema, - targetDialect = 'postgresql', + targetDialect = "postgresql", deleteExistingTables = T, createTables = T, - tablePrefix = 'c_', - tempEmulationSchema = getOption("sqlRenderTempEmulationSchema") -){ + tablePrefix = "c_", + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema")) { errorMessages <- checkmate::makeAssertCollection() .checkTablePrefix( tablePrefix = tablePrefix, @@ -172,8 +166,8 @@ createCharacterizationTables <- function( checkmate::reportAssertions(errorMessages) - if(deleteExistingTables){ - message('Deleting existing tables') + if (deleteExistingTables) { + message("Deleting existing tables") tables <- getResultTables() tables <- paste0(tablePrefix, tables) @@ -184,9 +178,9 @@ createCharacterizationTables <- function( ) ) - for(tb in tables){ - if(tb %in% alltables){ - sql <- 'DELETE FROM @my_schema.@table' + for (tb in tables) { + if (tb %in% alltables) { + sql <- "DELETE FROM @my_schema.@table" sql <- SqlRender::render( sql = sql, my_schema = resultSchema, @@ -202,7 +196,7 @@ createCharacterizationTables <- function( sql = sql ) - sql <- 'DROP TABLE @my_schema.@table' + sql <- "DROP TABLE @my_schema.@table" sql <- SqlRender::render( sql = sql, my_schema = resultSchema, @@ -218,13 +212,11 @@ createCharacterizationTables <- function( sql = sql ) } - } - } - if(createTables){ - ParallelLogger::logInfo('Creating characterization results tables') + if (createTables) { + ParallelLogger::logInfo("Creating characterization results tables") renderedSql <- SqlRender::loadRenderTranslateSql( sqlFilename = "ResultTables.sql", packageName = "Characterization", @@ -241,7 +233,6 @@ createCharacterizationTables <- function( # add database migration here in the future } - } #' Exports all tables in the result database to csv files @@ -274,11 +265,9 @@ exportDatabaseToCsv <- function( targetDialect = NULL, tablePrefix = "c_", filePrefix = NULL, - tempEmulationSchema = NULL, + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), saveDirectory, - minMeanCovariateValue = 0.001 -){ - + minMeanCovariateValue = 0.001) { errorMessages <- checkmate::makeAssertCollection() .checkConnectionDetails(connectionDetails, errorMessages) .checkTablePrefix( @@ -291,7 +280,7 @@ exportDatabaseToCsv <- function( } if (is.null(filePrefix)) { - filePrefix = '' + filePrefix <- "" } # connect to result database @@ -303,7 +292,7 @@ exportDatabaseToCsv <- function( ) # create the folder to save the csv files - if(!dir.exists(saveDirectory)){ + if (!dir.exists(saveDirectory)) { dir.create( path = saveDirectory, recursive = T @@ -317,55 +306,116 @@ exportDatabaseToCsv <- function( tables <- getResultTables() # extract result per table - for(table in tables){ - message(paste0("Exporting ", table)) - sql <- "select * from @resultSchema.@appendtotable@tablename;" + for (table in tables) { + ParallelLogger::logInfo(paste0("Exporting rows from ", table, " to csv file")) + # get row count and figure out number of loops + sql <- "select count(*) as N from @resultSchema.@appendtotable@tablename;" sql <- SqlRender::render( sql = sql, resultSchema = resultSchema, appendtotable = tablePrefix, tablename = table ) - resultSet <- DatabaseConnector::dbSendQuery(connection, sql) - tryCatch({ - i <- 1 - while (i == 1 || !DatabaseConnector::dbHasCompleted(resultSet)) { - start <- format(x = (i-1)*maxRowCount+1, scientific = F, big.mark = ",") - end <- format(x = maxRowCount*i, scientific = F, big.mark = ",") - message(paste0(" -- Rows ", start, " to ", end)) - result <- DatabaseConnector::dbFetch(resultSet, n = maxRowCount) - if (table == "covariates" && minMeanCovariateValue > 0) { - result <- result %>% - dplyr::filter(.data$average_value >= minMeanCovariateValue) - } - result <- formatDouble(result) - # save the results as a csv - readr::write_csv( - x = result, - file = file.path(saveDirectory, paste0(tolower(filePrefix), table,'.csv')), - append = (i > 1) - ) - i <- i + 1 + sql <- SqlRender::translate( + sql = sql, + targetDialect = connectionDetails$dbms, + tempEmulationSchema = tempEmulationSchema + ) + countN <- DatabaseConnector::querySql( + connection = connection, + sql = sql, + snakeCaseToCamelCase = F + )$N + + # get column names + sql <- "select * from @resultSchema.@appendtotable@tablename where 1=0;" + sql <- SqlRender::render( + sql = sql, + resultSchema = resultSchema, + appendtotable = tablePrefix, + tablename = table + ) + sql <- SqlRender::translate( + sql = sql, + targetDialect = connectionDetails$dbms, + tempEmulationSchema = tempEmulationSchema + ) + cnames <- colnames(DatabaseConnector::querySql( + connection = connection, + sql = sql, + snakeCaseToCamelCase = F + )) + + inds <- floor(countN / maxRowCount) + tableAppend <- F + # NOTE: If the table has 0 rows (countN == 0), + # then setting the txtProgressBar will fail since + # min < max. So, setting max = countN+1 for this + # reason. + pb <- utils::txtProgressBar(min = 0, max = countN + 1, initial = 0) + + for (i in 1:length(inds)) { + startRow <- (i - 1) * maxRowCount + 1 + endRow <- min(i * maxRowCount, countN) + + sql <- "select @cnames from + (select *, + ROW_NUMBER() OVER(ORDER BY @cnames) AS row + from @resultSchema.@appendtotable@tablename + ) temp + where + temp.row >= @start_row and + temp.row <= @end_row;" + sql <- SqlRender::render( + sql = sql, + resultSchema = resultSchema, + appendtotable = tablePrefix, + tablename = table, + cnames = paste(cnames, collapse = ","), + start_row = startRow, + end_row = endRow + ) + sql <- SqlRender::translate( + sql = sql, + targetDialect = connectionDetails$dbms, + tempEmulationSchema = tempEmulationSchema + ) + result <- DatabaseConnector::querySql( + connection = connection, + sql = sql, + snakeCaseToCamelCase = F + ) + result <- formatDouble(result) + + # save the results as a csv + readr::write_csv( + x = result, + file = file.path(saveDirectory, paste0(tolower(filePrefix), table, ".csv")), + append = tableAppend + ) + tableAppend <- T + # NOTE: Handling progresss bar per note on txtProgressBar + # above. Otherwise the progress bar doesn't show that it completed. + if (endRow == countN) { + utils::setTxtProgressBar(pb, countN + 1) + } else { + utils::setTxtProgressBar(pb, endRow) } - }, - error = function(e) { - message(paste0("ERROR in export to csv: ", e$message)); - }, - finally = { - DatabaseConnector::dbClearResult(resultSet) - }) + } + close(pb) } + invisible(saveDirectory) } -getResultTables <- function(){ +getResultTables <- function() { return( unique( readr::read_csv( file = system.file( - 'settings', - 'resultsDataModelSpecification.csv', - package = 'Characterization' + "settings", + "resultsDataModelSpecification.csv", + package = "Characterization" ), show_col_types = FALSE )$table_name @@ -384,4 +434,3 @@ formatDouble <- function(x, scientific = F, ...) { return(x) } - diff --git a/R/DechallengeRechallenge.R b/R/DechallengeRechallenge.R index 24bf0b7..4ad299b 100644 --- a/R/DechallengeRechallenge.R +++ b/R/DechallengeRechallenge.R @@ -1,4 +1,4 @@ -# Copyright 2022 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of Characterization # @@ -26,23 +26,21 @@ #' #' @export createDechallengeRechallengeSettings <- function( - targetIds, - outcomeIds, - dechallengeStopInterval = 30, - dechallengeEvaluationWindow = 30 -){ - + targetIds, + outcomeIds, + dechallengeStopInterval = 30, + dechallengeEvaluationWindow = 30) { errorMessages <- checkmate::makeAssertCollection() # check targetIds is a vector of int/double .checkCohortIds( cohortIds = targetIds, - type = 'target', + type = "target", errorMessages = errorMessages - ) + ) # check outcomeIds is a vector of int/double .checkCohortIds( cohortIds = outcomeIds, - type = 'outcome', + type = "outcome", errorMessages = errorMessages ) @@ -53,7 +51,7 @@ createDechallengeRechallengeSettings <- function( finite = TRUE, any.missing = FALSE, len = 1, - .var.name = 'dechallengeStopInterval', + .var.name = "dechallengeStopInterval", add = errorMessages ) @@ -64,7 +62,7 @@ createDechallengeRechallengeSettings <- function( finite = TRUE, any.missing = FALSE, len = 1, - .var.name = 'dechallengeEvaluationWindow', + .var.name = "dechallengeEvaluationWindow", add = errorMessages ) @@ -78,7 +76,7 @@ createDechallengeRechallengeSettings <- function( dechallengeEvaluationWindow = dechallengeEvaluationWindow ) - class(result) <- 'dechallengeRechallengeSettings' + class(result) <- "dechallengeRechallengeSettings" return(result) } @@ -95,45 +93,43 @@ createDechallengeRechallengeSettings <- function( #' #' @export computeDechallengeRechallengeAnalyses <- function( - connectionDetails = NULL, - targetDatabaseSchema, - targetTable, - outcomeDatabaseSchema = targetDatabaseSchema, - outcomeTable = targetTable, - tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), - dechallengeRechallengeSettings, - databaseId = 'database 1' -) { - + connectionDetails = NULL, + targetDatabaseSchema, + targetTable, + outcomeDatabaseSchema = targetDatabaseSchema, + outcomeTable = targetTable, + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), + dechallengeRechallengeSettings, + databaseId = "database 1") { # check inputs errorMessages <- checkmate::makeAssertCollection() .checkConnectionDetails(connectionDetails, errorMessages) .checkCohortDetails( cohortDatabaseSchema = targetDatabaseSchema, cohortTable = targetTable, - type = 'target', - errorMessages = errorMessages - ) + type = "target", + errorMessages = errorMessages + ) .checkCohortDetails( cohortDatabaseSchema = outcomeDatabaseSchema, cohortTable = outcomeTable, - type = 'outcome', - errorMessages = errorMessages + type = "outcome", + errorMessages = errorMessages ) .checkTempEmulationSchema( tempEmulationSchema = tempEmulationSchema, - errorMessages = errorMessages + errorMessages = errorMessages ) .checkDechallengeRechallengeSettings( settings = dechallengeRechallengeSettings, - errorMessages = errorMessages - ) + errorMessages = errorMessages + ) valid <- checkmate::reportAssertions( collection = errorMessages - ) + ) - if(valid){ + if (valid) { # inputs all pass if getting here message("Inputs checked") @@ -144,7 +140,7 @@ computeDechallengeRechallengeAnalyses <- function( ) on.exit( DatabaseConnector::disconnect(connection) - ) + ) message("Computing dechallenge rechallenge results") sql <- SqlRender::loadRenderTranslateSql( @@ -157,8 +153,8 @@ computeDechallengeRechallengeAnalyses <- function( target_table = targetTable, outcome_database_schema = outcomeDatabaseSchema, outcome_table = outcomeTable, - target_ids = paste(dechallengeRechallengeSettings$targetCohortDefinitionIds, sep='', collapse = ','), - outcome_ids = paste(dechallengeRechallengeSettings$outcomeCohortDefinitionIds, sep='', collapse = ','), + target_ids = paste(dechallengeRechallengeSettings$targetCohortDefinitionIds, sep = "", collapse = ","), + outcome_ids = paste(dechallengeRechallengeSettings$outcomeCohortDefinitionIds, sep = "", collapse = ","), dechallenge_stop_interval = dechallengeRechallengeSettings$dechallengeStopInterval, dechallenge_evaluation_window = dechallengeRechallengeSettings$dechallengeEvaluationWindow ) @@ -167,17 +163,17 @@ computeDechallengeRechallengeAnalyses <- function( sql = sql ) - sql <- 'select * from #challenge;' + sql <- "select * from #challenge;" sql <- SqlRender::translate( sql = sql, - targetDialect = connection@dbms, + targetDialect = connection@dbms, tempEmulationSchema = tempEmulationSchema ) result <- DatabaseConnector::querySqlToAndromeda( connection = connection, andromeda = Andromeda::andromeda(), - andromedaTableName = 'dechallengeRechallenge', + andromedaTableName = "dechallengeRechallenge", sql = sql, snakeCaseToCamelCase = TRUE ) @@ -200,7 +196,7 @@ computeDechallengeRechallengeAnalyses <- function( paste0( "Computing dechallenge rechallenge for ", length(dechallengeRechallengeSettings$targetCohortDefinitionIds), " target ids and ", - length(dechallengeRechallengeSettings$outcomeCohortDefinitionIds),"outcome ids took ", + length(dechallengeRechallengeSettings$outcomeCohortDefinitionIds), "outcome ids took ", signif(delta, 3), " ", attr(delta, "units") ) @@ -225,44 +221,42 @@ computeDechallengeRechallengeAnalyses <- function( #' #' @export computeRechallengeFailCaseSeriesAnalyses <- function( - connectionDetails = NULL, - targetDatabaseSchema, - targetTable, - outcomeDatabaseSchema = targetDatabaseSchema, - outcomeTable = targetTable, - tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), - dechallengeRechallengeSettings, - databaseId = 'database 1', - showSubjectId = F -) { - + connectionDetails = NULL, + targetDatabaseSchema, + targetTable, + outcomeDatabaseSchema = targetDatabaseSchema, + outcomeTable = targetTable, + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), + dechallengeRechallengeSettings, + databaseId = "database 1", + showSubjectId = F) { # check inputs errorMessages <- checkmate::makeAssertCollection() .checkConnectionDetails(connectionDetails, errorMessages) .checkCohortDetails( cohortDatabaseSchema = targetDatabaseSchema, cohortTable = targetTable, - type = 'target', - errorMessages = errorMessages + type = "target", + errorMessages = errorMessages ) .checkCohortDetails( cohortDatabaseSchema = outcomeDatabaseSchema, cohortTable = outcomeTable, - type = 'outcome', - errorMessages = errorMessages + type = "outcome", + errorMessages = errorMessages ) .checkTempEmulationSchema( tempEmulationSchema = tempEmulationSchema, - errorMessages = errorMessages + errorMessages = errorMessages ) .checkDechallengeRechallengeSettings( settings = dechallengeRechallengeSettings, - errorMessages = errorMessages + errorMessages = errorMessages ) valid <- checkmate::reportAssertions(errorMessages) - if(valid){ + if (valid) { # inputs all pass if getting here message("Inputs checked") @@ -273,7 +267,7 @@ computeRechallengeFailCaseSeriesAnalyses <- function( ) on.exit( DatabaseConnector::disconnect(connection) - ) + ) message("Computing dechallenge rechallenge results") sql <- SqlRender::loadRenderTranslateSql( @@ -286,8 +280,8 @@ computeRechallengeFailCaseSeriesAnalyses <- function( target_table = targetTable, outcome_database_schema = outcomeDatabaseSchema, outcome_table = outcomeTable, - target_ids = paste(dechallengeRechallengeSettings$targetCohortDefinitionIds, sep='', collapse = ','), - outcome_ids = paste(dechallengeRechallengeSettings$outcomeCohortDefinitionIds, sep='', collapse = ','), + target_ids = paste(dechallengeRechallengeSettings$targetCohortDefinitionIds, sep = "", collapse = ","), + outcome_ids = paste(dechallengeRechallengeSettings$outcomeCohortDefinitionIds, sep = "", collapse = ","), dechallenge_stop_interval = dechallengeRechallengeSettings$dechallengeStopInterval, dechallenge_evaluation_window = dechallengeRechallengeSettings$dechallengeEvaluationWindow, show_subject_id = showSubjectId @@ -297,17 +291,17 @@ computeRechallengeFailCaseSeriesAnalyses <- function( sql = sql ) - sql <- 'select * from #fail_case_series;' + sql <- "select * from #fail_case_series;" sql <- SqlRender::translate( sql = sql, - targetDialect = connection@dbms, + targetDialect = connection@dbms, tempEmulationSchema = tempEmulationSchema ) result <- DatabaseConnector::querySqlToAndromeda( connection = connection, andromeda = Andromeda::andromeda(), - andromedaTableName = 'rechallengeFailCaseSeries', + andromedaTableName = "rechallengeFailCaseSeries", sql = sql, snakeCaseToCamelCase = TRUE ) @@ -330,7 +324,7 @@ computeRechallengeFailCaseSeriesAnalyses <- function( paste0( "Computing dechallenge failed case series for ", length(dechallengeRechallengeSettings$targetCohortDefinitionIds), " target IDs and ", - length(dechallengeRechallengeSettings$outcomeCohortDefinitionIds)," outcome IDs took ", + length(dechallengeRechallengeSettings$outcomeCohortDefinitionIds), " outcome IDs took ", signif(delta, 3), " ", attr(delta, "units") ) diff --git a/R/HelperFunctions.R b/R/HelperFunctions.R index 26eb408..973ec25 100644 --- a/R/HelperFunctions.R +++ b/R/HelperFunctions.R @@ -1,4 +1,4 @@ -# Copyright 2022 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of Characterization # @@ -15,25 +15,23 @@ # limitations under the License. .checkConnection <- function( - connection, - errorMessages - ) { + connection, + errorMessages) { checkmate::assertClass( x = connection, classes = "DatabaseConnectorConnection", add = errorMessages - ) + ) } .checkConnectionDetails <- function( - connectionDetails, - errorMessages - ) { + connectionDetails, + errorMessages) { if (inherits(connectionDetails, "connectionDetails")) { - checkmate::assertClass( - x = connectionDetails, - classes = "connectionDetails", - add = errorMessages + checkmate::assertClass( + x = connectionDetails, + classes = "connectionDetails", + add = errorMessages ) } else { checkmate::assertClass( @@ -41,48 +39,42 @@ classes = "ConnectionDetails", add = errorMessages ) - } } .checkDechallengeRechallengeSettings <- function( - settings, - errorMessages - ) { + settings, + errorMessages) { checkmate::assertClass( x = settings, classes = "dechallengeRechallengeSettings", add = errorMessages - ) + ) } .checkDechallengeRechallengeSettingsList <- function( - settings, - errorMessages -) { - - if(is.null(settings)){ + settings, + errorMessages) { + if (is.null(settings)) { return() } - if(inherits(settings, 'dechallengeRechallengeSettings')){ + if (inherits(settings, "dechallengeRechallengeSettings")) { settings <- list(settings) } - lapply(settings, function(x){ + lapply(settings, function(x) { checkmate::assertClass( x = x, classes = "dechallengeRechallengeSettings", add = errorMessages ) - } - ) + }) } .checkTimeToEventSettings <- function( - settings, - errorMessages -) { + settings, + errorMessages) { checkmate::assertClass( x = settings, classes = "timeToEventSettings", @@ -91,32 +83,28 @@ } .checkTimeToEventSettingsList <- function( - settings, - errorMessages -) { - - if(is.null(settings)){ + settings, + errorMessages) { + if (is.null(settings)) { return() } - if(inherits(settings,'timeToEventSettings')){ + if (inherits(settings, "timeToEventSettings")) { settings <- list(settings) } - lapply(settings, function(x){ + lapply(settings, function(x) { checkmate::assertClass( x = x, classes = "timeToEventSettings", add = errorMessages ) - } - ) + }) } .checkAggregateCovariateSettings <- function( - settings, - errorMessages -) { + settings, + errorMessages) { checkmate::assertClass( x = settings, classes = "aggregateCovariateSettings", @@ -125,32 +113,28 @@ } .checkAggregateCovariateSettingsList <- function( - settings, - errorMessages -) { - - if(is.null(settings)){ + settings, + errorMessages) { + if (is.null(settings)) { return() } - if(inherits(settings,'aggregateCovariateSettings')){ + if (inherits(settings, "aggregateCovariateSettings")) { settings <- list(settings) } - lapply(settings, function(x){ + lapply(settings, function(x) { checkmate::assertClass( x = x, classes = "aggregateCovariateSettings", add = errorMessages ) - } - ) + }) } .checkCharacterizationSettings <- function( - settings, - errorMessages -) { + settings, + errorMessages) { checkmate::assertClass( x = settings, classes = "characterizationSettings", @@ -158,45 +142,42 @@ ) } -.checkCohortDetails<- function( - cohortDatabaseSchema, - cohortTable, - type = 'cohort', - errorMessages - ) { +.checkCohortDetails <- function( + cohortDatabaseSchema, + cohortTable, + type = "cohort", + errorMessages) { checkmate::assertCharacter( x = cohortDatabaseSchema, len = 1, add = errorMessages, - .var.name = paste0(type, 'DatabaseSchema') - ) + .var.name = paste0(type, "DatabaseSchema") + ) checkmate::assertCharacter( x = cohortTable, len = 1, add = errorMessages, - .var.name = paste0(type, 'Table') - ) + .var.name = paste0(type, "Table") + ) } .checkCohortIds <- function( - cohortIds, - type = 'cohort', - errorMessages -) { + cohortIds, + type = "cohort", + errorMessages) { checkmate::assertNumeric( x = cohortIds, add = errorMessages, - .var.name = paste0(type, 'Id') + .var.name = paste0(type, "Id") ) } .checkTimeAtRisk <- function( - riskWindowStart, - startAnchor, - riskWindowEnd, - endAnchor, - errorMessages -) { + riskWindowStart, + startAnchor, + riskWindowEnd, + endAnchor, + errorMessages) { checkmate::assertInt(riskWindowStart, add = errorMessages) checkmate::assertChoice(startAnchor, c("cohort start", "cohort end"), add = errorMessages) checkmate::assertInt(riskWindowEnd, add = errorMessages) @@ -204,22 +185,20 @@ } .checkTempEmulationSchema <- function( - tempEmulationSchema, - errorMessages - ) { + tempEmulationSchema, + errorMessages) { checkmate::assertCharacter( x = tempEmulationSchema, len = 1, null.ok = TRUE, add = errorMessages - ) + ) } .checkTablePrefix <- function( tablePrefix, - errorMessages -) { + errorMessages) { checkmate::assertCharacter( pattern = "[a-zA-Z]_$", x = tablePrefix, @@ -234,27 +213,29 @@ .checkCovariateSettings <- function(covariateSettings, errorMessages) { if (class(covariateSettings) == "covariateSettings") { - checkmate::assertClass(x = covariateSettings, - classes = "covariateSettings", - add = errorMessages) + checkmate::assertClass( + x = covariateSettings, + classes = "covariateSettings", + add = errorMessages + ) } else { for (j in (1:length(covariateSettings))) { - checkmate::assertClass(x = covariateSettings[[j]], - classes = "covariateSettings", - add = errorMessages) + checkmate::assertClass( + x = covariateSettings[[j]], + classes = "covariateSettings", + add = errorMessages + ) } } - } .checkMinPriorObservation <- function( minPriorObservation, - errorMessages -) { + errorMessages) { checkmate::assertCount( x = minPriorObservation, null.ok = F, - .var.name = 'minPriorObservation', + .var.name = "minPriorObservation", add = errorMessages ) } diff --git a/R/RunCharacterization.R b/R/RunCharacterization.R index 531631c..94bc488 100644 --- a/R/RunCharacterization.R +++ b/R/RunCharacterization.R @@ -16,9 +16,7 @@ createCharacterizationSettings <- function( timeToEventSettings = NULL, dechallengeRechallengeSettings = NULL, - aggregateCovariateSettings = NULL -) -{ + aggregateCovariateSettings = NULL) { errorMessages <- checkmate::makeAssertCollection() .checkTimeToEventSettingsList( settings = timeToEventSettings, @@ -67,13 +65,12 @@ createCharacterizationSettings <- function( #' @param fileName The location to save the json settings #' #' @return -#' Returns the location of the drectory containing the json settings +#' Returns the location of the directory containing the json settings #' #' @export saveCharacterizationSettings <- function( settings, - fileName -) { + fileName) { ParallelLogger::saveSettingsToJson( object = settings, fileName = fileName @@ -96,9 +93,7 @@ saveCharacterizationSettings <- function( #' #' @export loadCharacterizationSettings <- function( - fileName -) { - + fileName) { settings <- ParallelLogger::loadSettingsFromJson( fileName = fileName ) @@ -122,7 +117,7 @@ loadCharacterizationSettings <- function( #' @param characterizationSettings The study settings created using \code{createCharacterizationSettings} #' @param saveDirectory The location to save the results to #' @param tablePrefix A string to append the tables in the results -#' @param databaseId The unqiue identifier for the cdm database +#' @param databaseId The unique identifier for the cdm database #' @param showSubjectId Whether to include subjectId of failed rechallenge case series or hide #' @param minCellCount The minimum count value that is calculated #' @@ -144,8 +139,7 @@ runCharacterizationAnalyses <- function( tablePrefix = "c_", databaseId = "1", showSubjectId = F, - minCellCount = 0 -) { + minCellCount = 0) { # inputs checks errorMessages <- checkmate::makeAssertCollection() .checkCharacterizationSettings( @@ -155,10 +149,10 @@ runCharacterizationAnalyses <- function( .checkTablePrefix( tablePrefix = tablePrefix, errorMessages = errorMessages - ) + ) checkmate::reportAssertions( errorMessages - ) + ) # create the Database conn <- createSqliteDatabase( @@ -166,7 +160,7 @@ runCharacterizationAnalyses <- function( ) on.exit( DatabaseConnector::disconnect(conn) - ) + ) createCharacterizationTables( conn = conn, @@ -179,7 +173,6 @@ runCharacterizationAnalyses <- function( if (!is.null(characterizationSettings$timeToEventSettings)) { for (i in 1:length(characterizationSettings$timeToEventSettings)) { - message("Running time to event analysis ", i) result <- tryCatch( @@ -197,7 +190,7 @@ runCharacterizationAnalyses <- function( ) }, error = function(e) { - message(paste0("ERROR in time-to-event analysis: ", e$message)); + message(paste0("ERROR in time-to-event analysis: ", e$message)) return(NULL) } ) @@ -222,10 +215,9 @@ runCharacterizationAnalyses <- function( andromedaObject = result$timeToEvent, tablePrefix = tablePrefix, minCellCount = minCellCount, - minCellCountColumns = list('numEvents') + minCellCountColumns = list("numEvents") ) } - } } @@ -247,7 +239,7 @@ runCharacterizationAnalyses <- function( ) }, error = function(e) { - message(paste0("ERROR in dechallenge rechallenge analysis: ", e$message)); + message(paste0("ERROR in dechallenge rechallenge analysis: ", e$message)) return(NULL) } ) @@ -273,12 +265,12 @@ runCharacterizationAnalyses <- function( tablePrefix = tablePrefix, minCellCount = minCellCount, minCellCountColumns = list( - c('numCases'), - c('dechallengeAttempt'), - c('dechallengeFail', 'dechallengeSuccess'), - c('rechallengeAttempt'), - c('rechallengeFail', 'rechallengeSuccess') - ) + c("numCases"), + c("dechallengeAttempt"), + c("dechallengeFail", "dechallengeSuccess"), + c("rechallengeAttempt"), + c("rechallengeFail", "rechallengeSuccess") + ) ) } @@ -300,7 +292,7 @@ runCharacterizationAnalyses <- function( ) }, error = function(e) { - message(paste0("ERROR in rechallenge failed case analysis: ", e$message)); + message(paste0("ERROR in rechallenge failed case analysis: ", e$message)) return(NULL) } ) @@ -350,8 +342,8 @@ runCharacterizationAnalyses <- function( ) }, error = function(e) { - message(paste0("ERROR in aggregate covariate analyses: ", e$message)); - message(e); + message(paste0("ERROR in aggregate covariate analyses: ", e$message)) + message(e) return(NULL) } ) @@ -417,7 +409,7 @@ runCharacterizationAnalyses <- function( tablePrefix = tablePrefix, minCellCount = minCellCount, minCellCountColumns = list( - c('sumValue') #c('SUM_VALUE') #AVERAGE_VALUE + c("sumValue") # c('SUM_VALUE') #AVERAGE_VALUE ) ) } @@ -431,7 +423,7 @@ runCharacterizationAnalyses <- function( tablePrefix = tablePrefix, minCellCount = minCellCount, minCellCountColumns = list( - c('countValue') + c("countValue") ) ) } diff --git a/R/SaveLoad.R b/R/SaveLoad.R index f6c2e23..af7bb4e 100644 --- a/R/SaveLoad.R +++ b/R/SaveLoad.R @@ -1,4 +1,4 @@ -# Copyright 2022 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of Characterization # @@ -32,8 +32,7 @@ colnamesLower <- function(data) { #' @export saveTimeToEventAnalyses <- function( result, - fileName -) { + fileName) { Andromeda::saveAndromeda( andromeda = result, fileName = fileName, @@ -56,19 +55,17 @@ saveTimeToEventAnalyses <- function( exportTimeToEventToCsv <- function( result, saveDirectory, - minCellCount = 0 -) { + minCellCount = 0) { if (!dir.exists(saveDirectory)) { dir.create( path = saveDirectory, recursive = T - ) + ) } Andromeda::batchApply( tbl = result$timeToEvent, fun = function(x) { - append <- file.exists( file.path( saveDirectory, @@ -79,14 +76,14 @@ exportTimeToEventToCsv <- function( dat <- as.data.frame( x %>% dplyr::collect() - ) + ) colnames(dat) <- SqlRender::camelCaseToSnakeCase( string = colnames(dat) ) - if(sum(dat$NUM_EVENTS < minCellCount)>0){ - ParallelLogger::logInfo(paste0('Removing NUM_EVENTS less than ', minCellCount)) + if (sum(dat$NUM_EVENTS < minCellCount) > 0) { + ParallelLogger::logInfo(paste0("Removing NUM_EVENTS less than ", minCellCount)) dat$NUM_EVENTS[dat$NUM_EVENTS < minCellCount] <- -1 } @@ -95,10 +92,9 @@ exportTimeToEventToCsv <- function( file = file.path( saveDirectory, "time_to_event.csv" - ), + ), append = append ) - } ) @@ -134,8 +130,7 @@ loadTimeToEventAnalyses <- function(fileName) { #' @export saveDechallengeRechallengeAnalyses <- function( result, - fileName -) { + fileName) { Andromeda::saveAndromeda( andromeda = result, fileName = fileName, @@ -157,8 +152,7 @@ saveDechallengeRechallengeAnalyses <- function( #' @export saveRechallengeFailCaseSeriesAnalyses <- function( result, - fileName -) { + fileName) { Andromeda::saveAndromeda( andromeda = result, fileName = fileName, @@ -178,8 +172,7 @@ saveRechallengeFailCaseSeriesAnalyses <- function( #' #' @export loadDechallengeRechallengeAnalyses <- function( - fileName -) { + fileName) { result <- Andromeda::loadAndromeda(fileName) return(result) } @@ -193,8 +186,7 @@ loadDechallengeRechallengeAnalyses <- function( #' #' @export loadRechallengeFailCaseSeriesAnalyses <- function( - fileName -) { + fileName) { result <- Andromeda::loadAndromeda(fileName) return(result) } @@ -212,9 +204,7 @@ loadRechallengeFailCaseSeriesAnalyses <- function( exportDechallengeRechallengeToCsv <- function( result, saveDirectory, - minCellCount = 0 -) { - + minCellCount = 0) { countN <- dplyr::pull( dplyr::count(result$dechallengeRechallenge) ) @@ -232,49 +222,49 @@ exportDechallengeRechallengeToCsv <- function( dat <- as.data.frame( x %>% dplyr::collect() - ) + ) colnames(dat) <- SqlRender::camelCaseToSnakeCase( string = colnames(dat) ) removeInd <- dat$NUM_EVENTS < minCellCount - if(sum(removeInd) > 0){ - ParallelLogger::logInfo(paste0('Removing NUM_EVENTS counts less than ', minCellCount)) - if(sum(removeInd) > 0){ - dat$NUM_CASES[removeInd] <- -1 - } + if (sum(removeInd) > 0) { + ParallelLogger::logInfo(paste0("Removing NUM_EVENTS counts less than ", minCellCount)) + if (sum(removeInd) > 0) { + dat$NUM_CASES[removeInd] <- -1 + } } removeInd <- dat$DECHALLENGE_ATTEMPT < minCellCount - if(sum(removeInd) > 0){ - ParallelLogger::logInfo(paste0('Removing DECHALLENGE_ATTEMPT counts less than ', minCellCount)) - if(sum(removeInd) > 0){ + if (sum(removeInd) > 0) { + ParallelLogger::logInfo(paste0("Removing DECHALLENGE_ATTEMPT counts less than ", minCellCount)) + if (sum(removeInd) > 0) { dat$DECHALLENGE_ATTEMPT[removeInd] <- -1 } } removeInd <- dat$DECHALLENGE_FAIL < minCellCount | dat$DECHALLENGE_SUCCESS < minCellCount - if(sum(removeInd) > 0){ - ParallelLogger::logInfo(paste0('Removing DECHALLENGE FAIL or SUCCESS counts less than ', minCellCount)) - if(sum(removeInd) > 0){ + if (sum(removeInd) > 0) { + ParallelLogger::logInfo(paste0("Removing DECHALLENGE FAIL or SUCCESS counts less than ", minCellCount)) + if (sum(removeInd) > 0) { dat$DECHALLENGE_FAIL[removeInd] <- -1 dat$DECHALLENGE_SUCCESS[removeInd] <- -1 } } removeInd <- dat$RECHALLENGE_ATTEMPT < minCellCount - if(sum(removeInd) > 0){ - ParallelLogger::logInfo(paste0('Removing RECHALLENGE_ATTEMPT counts less than ', minCellCount)) - if(sum(removeInd) > 0){ + if (sum(removeInd) > 0) { + ParallelLogger::logInfo(paste0("Removing RECHALLENGE_ATTEMPT counts less than ", minCellCount)) + if (sum(removeInd) > 0) { dat$RECHALLENGE_ATTEMPT[removeInd] <- -1 } } removeInd <- dat$RECHALLENGE_FAIL < minCellCount | dat$RECHALLENGE_SUCCESS < minCellCount - if(sum(removeInd) > 0){ - ParallelLogger::logInfo(paste0('Removing RECHALLENGE FAIL or SUCCESS counts less than ', minCellCount)) - if(sum(removeInd) > 0){ + if (sum(removeInd) > 0) { + ParallelLogger::logInfo(paste0("Removing RECHALLENGE FAIL or SUCCESS counts less than ", minCellCount)) + if (sum(removeInd) > 0) { dat$RECHALLENGE_FAIL[removeInd] <- -1 dat$RECHALLENGE_SUCCESS[removeInd] <- -1 } @@ -288,7 +278,6 @@ exportDechallengeRechallengeToCsv <- function( ), append = append ) - } ) @@ -311,8 +300,7 @@ exportDechallengeRechallengeToCsv <- function( #' @export exportRechallengeFailCaseSeriesToCsv <- function( result, - saveDirectory -) { + saveDirectory) { if (!dir.exists(saveDirectory)) { dir.create( path = saveDirectory, @@ -322,39 +310,37 @@ exportRechallengeFailCaseSeriesToCsv <- function( countN <- dplyr::pull( dplyr::count(result$rechallengeFailCaseSeries) - ) + ) message("Writing ", countN, " rows to csv") Andromeda::batchApply( tbl = result$rechallengeFailCaseSeries, fun = function(x) { - append <- file.exists( file.path( saveDirectory, "rechallenge_fail_case_series.csv" - ) ) + ) dat <- as.data.frame( x %>% dplyr::collect() - ) + ) colnames(dat) <- SqlRender::camelCaseToSnakeCase( string = colnames(dat) - ) + ) readr::write_csv( x = dat, file = file.path( saveDirectory, "rechallenge_fail_case_series.csv" - ), + ), append = append ) - } ) @@ -377,8 +363,7 @@ exportRechallengeFailCaseSeriesToCsv <- function( #' @export saveAggregateCovariateAnalyses <- function( result, - fileName -) { + fileName) { Andromeda::saveAndromeda( andromeda = result, fileName = fileName, @@ -397,8 +382,7 @@ saveAggregateCovariateAnalyses <- function( #' #' @export loadAggregateCovariateAnalyses <- function( - fileName -) { + fileName) { result <- Andromeda::loadAndromeda( fileName = fileName ) @@ -419,8 +403,7 @@ loadAggregateCovariateAnalyses <- function( exportAggregateCovariateToCsv <- function( result, saveDirectory, - minCellCount = 0 -) { + minCellCount = 0) { if (!dir.exists(saveDirectory)) { dir.create(saveDirectory, recursive = T) } @@ -429,7 +412,6 @@ exportAggregateCovariateToCsv <- function( Andromeda::batchApply( tbl = result$settings, fun = function(x) { - append <- file.exists( file.path( saveDirectory, @@ -454,14 +436,12 @@ exportAggregateCovariateToCsv <- function( ), append = append ) - } ) # cohort details Andromeda::batchApply( tbl = result$cohortCounts, fun = function(x) { - append <- file.exists( file.path( saveDirectory, @@ -486,7 +466,6 @@ exportAggregateCovariateToCsv <- function( ), append = append ) - } ) @@ -494,7 +473,6 @@ exportAggregateCovariateToCsv <- function( Andromeda::batchApply( tbl = result$cohortDetails, fun = function(x) { - append <- file.exists( file.path( saveDirectory, @@ -519,7 +497,6 @@ exportAggregateCovariateToCsv <- function( ), append = append ) - } ) @@ -527,7 +504,6 @@ exportAggregateCovariateToCsv <- function( Andromeda::batchApply( tbl = result$analysisRef, fun = function(x) { - append <- file.exists( file.path( saveDirectory, @@ -538,7 +514,7 @@ exportAggregateCovariateToCsv <- function( dat <- as.data.frame( x %>% dplyr::collect() - ) + ) colnames(dat) <- SqlRender::camelCaseToSnakeCase( string = colnames(dat) @@ -552,7 +528,6 @@ exportAggregateCovariateToCsv <- function( ), append = append ) - } ) @@ -560,7 +535,6 @@ exportAggregateCovariateToCsv <- function( Andromeda::batchApply( tbl = result$covariateRef, fun = function(x) { - append <- file.exists( file.path( saveDirectory, @@ -571,7 +545,7 @@ exportAggregateCovariateToCsv <- function( dat <- as.data.frame( x %>% dplyr::collect() - ) + ) colnames(dat) <- SqlRender::camelCaseToSnakeCase( string = colnames(dat) @@ -585,7 +559,6 @@ exportAggregateCovariateToCsv <- function( ), append = append ) - } ) @@ -593,27 +566,26 @@ exportAggregateCovariateToCsv <- function( Andromeda::batchApply( tbl = result$covariates, fun = function(x) { - append <- file.exists( file.path( saveDirectory, "covariates.csv" - ) ) + ) dat <- as.data.frame( x %>% dplyr::collect() - ) + ) colnames(dat) <- SqlRender::camelCaseToSnakeCase( string = colnames(dat) ) removeInd <- dat$SUM_VALUE < minCellCount - if(sum(removeInd) > 0){ - ParallelLogger::logInfo(paste0('Removing SUM_VALUE counts less than ', minCellCount)) - if(sum(removeInd) > 0){ + if (sum(removeInd) > 0) { + ParallelLogger::logInfo(paste0("Removing SUM_VALUE counts less than ", minCellCount)) + if (sum(removeInd) > 0) { dat$SUM_VALUE[removeInd] <- -1 dat$AVERAGE_VALUE[removeInd] <- -1 } @@ -627,7 +599,6 @@ exportAggregateCovariateToCsv <- function( ), append = append ) - } ) @@ -635,7 +606,6 @@ exportAggregateCovariateToCsv <- function( Andromeda::batchApply( tbl = result$covariatesContinuous, fun = function(x) { - append <- file.exists( file.path( saveDirectory, @@ -646,16 +616,16 @@ exportAggregateCovariateToCsv <- function( dat <- as.data.frame( x %>% dplyr::collect() - ) + ) colnames(dat) <- SqlRender::camelCaseToSnakeCase( string = colnames(dat) ) removeInd <- dat$COUNT_VALUE < minCellCount - if(sum(removeInd) > 0){ - ParallelLogger::logInfo(paste0('Removing COUNT_VALUE counts less than ', minCellCount)) - if(sum(removeInd) > 0){ + if (sum(removeInd) > 0) { + ParallelLogger::logInfo(paste0("Removing COUNT_VALUE counts less than ", minCellCount)) + if (sum(removeInd) > 0) { dat$COUNT_VALUE[removeInd] <- -1 } } @@ -668,13 +638,13 @@ exportAggregateCovariateToCsv <- function( ), append = append ) - } ) invisible( file.path( saveDirectory, - c("cohort_details.csv", + c( + "cohort_details.csv", "settings.csv", "analysis_ref.csv", "covariate_ref.csv", diff --git a/R/TimeToEvent.R b/R/TimeToEvent.R index 3c9d7b9..5affa92 100644 --- a/R/TimeToEvent.R +++ b/R/TimeToEvent.R @@ -1,4 +1,4 @@ -# Copyright 2022 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of Characterization # @@ -24,22 +24,20 @@ #' #' @export createTimeToEventSettings <- function( - targetIds, - outcomeIds -){ - + targetIds, + outcomeIds) { # check indicationIds errorMessages <- checkmate::makeAssertCollection() # check targetIds is a vector of int/double .checkCohortIds( cohortIds = targetIds, - type = 'target', + type = "target", errorMessages = errorMessages ) # check outcomeIds is a vector of int/double .checkCohortIds( cohortIds = outcomeIds, - type = 'outcome', + type = "outcome", errorMessages = errorMessages ) checkmate::reportAssertions(errorMessages) @@ -51,7 +49,7 @@ createTimeToEventSettings <- function( outcomeIds = outcomeIds ) - class(result) <- 'timeToEventSettings' + class(result) <- "timeToEventSettings" return(result) } @@ -69,35 +67,33 @@ createTimeToEventSettings <- function( #' #' @export computeTimeToEventAnalyses <- function( - connectionDetails = NULL, - targetDatabaseSchema, - targetTable, - outcomeDatabaseSchema = targetDatabaseSchema, - outcomeTable = targetTable, - tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), - cdmDatabaseSchema, - timeToEventSettings, - databaseId = 'database 1' -) { - + connectionDetails = NULL, + targetDatabaseSchema, + targetTable, + outcomeDatabaseSchema = targetDatabaseSchema, + outcomeTable = targetTable, + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), + cdmDatabaseSchema, + timeToEventSettings, + databaseId = "database 1") { # check inputs errorMessages <- checkmate::makeAssertCollection() .checkConnectionDetails(connectionDetails, errorMessages) .checkCohortDetails( cohortDatabaseSchema = targetDatabaseSchema, cohortTable = targetTable, - type = 'target', - errorMessages = errorMessages + type = "target", + errorMessages = errorMessages ) .checkCohortDetails( cohortDatabaseSchema = outcomeDatabaseSchema, cohortTable = outcomeTable, - type = 'outcome', - errorMessages = errorMessages + type = "outcome", + errorMessages = errorMessages ) .checkTempEmulationSchema( tempEmulationSchema = tempEmulationSchema, - errorMessages = errorMessages + errorMessages = errorMessages ) .checkTimeToEventSettings( settings = timeToEventSettings, @@ -106,7 +102,7 @@ computeTimeToEventAnalyses <- function( valid <- checkmate::reportAssertions(errorMessages) - if(valid){ + if (valid) { start <- Sys.time() connection <- DatabaseConnector::connect( @@ -114,7 +110,7 @@ computeTimeToEventAnalyses <- function( ) on.exit( DatabaseConnector::disconnect(connection) - ) + ) # upload table to #cohort_settings message("Uploading #cohort_settings") @@ -155,10 +151,10 @@ computeTimeToEventAnalyses <- function( sql = sql ) - sql <- 'select * from #two_tte_summary;' + sql <- "select * from #two_tte_summary;" sql <- SqlRender::translate( sql = sql, - targetDialect = connection@dbms, + targetDialect = connection@dbms, tempEmulationSchema = tempEmulationSchema ) @@ -166,7 +162,7 @@ computeTimeToEventAnalyses <- function( connection = connection, sql = sql, andromeda = Andromeda::andromeda(), - andromedaTableName = 'timeToEvent', + andromedaTableName = "timeToEvent", snakeCaseToCamelCase = TRUE ) diff --git a/R/ViewShiny.R b/R/ViewShiny.R index a9c3290..3eea909 100644 --- a/R/ViewShiny.R +++ b/R/ViewShiny.R @@ -12,9 +12,7 @@ #' @export viewCharacterization <- function( resultLocation, - cohortDefinitionSet = NULL - ) { - + cohortDefinitionSet = NULL) { databaseSettings <- prepareCharacterizationShiny( resultLocation = resultLocation, cohortDefinitionSet = cohortDefinitionSet @@ -25,12 +23,11 @@ viewCharacterization <- function( prepareCharacterizationShiny <- function( resultLocation, - cohortDefinitionSet - ){ - server <- file.path(resultLocation, 'sqliteCharacterization', 'sqlite.sqlite') + cohortDefinitionSet) { + server <- file.path(resultLocation, "sqliteCharacterization", "sqlite.sqlite") connectionDetailsSettings <- list( - dbms = 'sqlite', + dbms = "sqlite", server = server ) @@ -42,24 +39,24 @@ prepareCharacterizationShiny <- function( con <- DatabaseConnector::connect(connectionDetails) on.exit(DatabaseConnector::disconnect(con)) - tables <- tolower(DatabaseConnector::getTableNames(con, 'main')) + tables <- tolower(DatabaseConnector::getTableNames(con, "main")) - if(!'cg_cohort_definition' %in% tables){ + if (!"cg_cohort_definition" %in% tables) { cohortIds <- unique( c( - DatabaseConnector::querySql(con, 'select distinct TARGET_COHORT_ID from c_cohort_details where TARGET_COHORT_ID != 0;')$TARGET_COHORT_ID, - DatabaseConnector::querySql(con, 'select distinct OUTCOME_COHORT_ID from c_cohort_details where OUTCOME_COHORT_ID != 0;')$OUTCOME_COHORT_ID, - DatabaseConnector::querySql(con, 'select distinct TARGET_COHORT_DEFINITION_ID from c_time_to_event;')$TARGET_COHORT_DEFINITION_ID, - DatabaseConnector::querySql(con, 'select distinct OUTCOME_COHORT_DEFINITION_ID from c_time_to_event;')$OUTCOME_COHORT_DEFINITION_ID, - DatabaseConnector::querySql(con, 'select distinct TARGET_COHORT_DEFINITION_ID from c_rechallenge_fail_case_series;')$TARGET_COHORT_DEFINITION_ID, - DatabaseConnector::querySql(con, 'select distinct OUTCOME_COHORT_DEFINITION_ID from c_rechallenge_fail_case_series;')$OUTCOME_COHORT_DEFINITION_ID + DatabaseConnector::querySql(con, "select distinct TARGET_COHORT_ID from c_cohort_details where TARGET_COHORT_ID != 0;")$TARGET_COHORT_ID, + DatabaseConnector::querySql(con, "select distinct OUTCOME_COHORT_ID from c_cohort_details where OUTCOME_COHORT_ID != 0;")$OUTCOME_COHORT_ID, + DatabaseConnector::querySql(con, "select distinct TARGET_COHORT_DEFINITION_ID from c_time_to_event;")$TARGET_COHORT_DEFINITION_ID, + DatabaseConnector::querySql(con, "select distinct OUTCOME_COHORT_DEFINITION_ID from c_time_to_event;")$OUTCOME_COHORT_DEFINITION_ID, + DatabaseConnector::querySql(con, "select distinct TARGET_COHORT_DEFINITION_ID from c_rechallenge_fail_case_series;")$TARGET_COHORT_DEFINITION_ID, + DatabaseConnector::querySql(con, "select distinct OUTCOME_COHORT_DEFINITION_ID from c_rechallenge_fail_case_series;")$OUTCOME_COHORT_DEFINITION_ID ) ) DatabaseConnector::insertTable( connection = con, - databaseSchema = 'main', - tableName = 'cg_COHORT_DEFINITION', + databaseSchema = "main", + tableName = "cg_COHORT_DEFINITION", data = data.frame( cohortDefinitionId = cohortIds, cohortName = getCohortNames(cohortIds, cohortDefinitionSet) @@ -68,51 +65,51 @@ prepareCharacterizationShiny <- function( ) } - if(!'database_meta_data' %in% tables){ + if (!"database_meta_data" %in% tables) { dbIds <- unique( c( - DatabaseConnector::querySql(con, 'select distinct DATABASE_ID from c_analysis_ref;')$DATABASE_ID, - DatabaseConnector::querySql(con, 'select distinct DATABASE_ID from c_dechallenge_rechallenge;')$DATABASE_ID, - DatabaseConnector::querySql(con, 'select distinct DATABASE_ID from c_time_to_event;')$DATABASE_ID + DatabaseConnector::querySql(con, "select distinct DATABASE_ID from c_analysis_ref;")$DATABASE_ID, + DatabaseConnector::querySql(con, "select distinct DATABASE_ID from c_dechallenge_rechallenge;")$DATABASE_ID, + DatabaseConnector::querySql(con, "select distinct DATABASE_ID from c_time_to_event;")$DATABASE_ID ) ) DatabaseConnector::insertTable( connection = con, - databaseSchema = 'main', - tableName = 'DATABASE_META_DATA', + databaseSchema = "main", + tableName = "DATABASE_META_DATA", data = data.frame( databaseId = dbIds, - cdmSourceAbbreviation = paste0('database ', dbIds) + cdmSourceAbbreviation = paste0("database ", dbIds) ), camelCaseToSnakeCase = T ) } - if(!'i_incidence_summary' %in% tables){ - - x <- c("refId", "databaseId", "sourceName", - "targetCohortDefinitionId", "targetName", "tarId", - "tarStartWith", "tarStartOffset", "tarEndWith", "tarEndOffset", - "subgroupId", 'subgroupName', - 'outcomeId','outcomeCohortDefinitionId', 'outcomeName', - 'clean_window', - 'ageId', 'ageGroupName', - 'genderId', 'genderName', - 'startYear', 'personsAtRiskPe', 'personsAtRisk', - 'personDaysPe', 'personDays', - 'personOutcomesPe', 'personOutcomes', - 'outcomesPe', 'outcomes', - 'incidenceProportionP100p', - 'incidenceRateP100py' + if (!"i_incidence_summary" %in% tables) { + x <- c( + "refId", "databaseId", "sourceName", + "targetCohortDefinitionId", "targetName", "tarId", + "tarStartWith", "tarStartOffset", "tarEndWith", "tarEndOffset", + "subgroupId", "subgroupName", + "outcomeId", "outcomeCohortDefinitionId", "outcomeName", + "clean_window", + "ageId", "ageGroupName", + "genderId", "genderName", + "startYear", "personsAtRiskPe", "personsAtRisk", + "personDaysPe", "personDays", + "personOutcomesPe", "personOutcomes", + "outcomesPe", "outcomes", + "incidenceProportionP100p", + "incidenceRateP100py" ) df <- data.frame(matrix(ncol = length(x), nrow = 0)) colnames(df) <- x DatabaseConnector::insertTable( connection = con, - databaseSchema = 'main', - tableName = 'i_incidence_summary', + databaseSchema = "main", + tableName = "i_incidence_summary", data = df, camelCaseToSnakeCase = T ) @@ -120,11 +117,11 @@ prepareCharacterizationShiny <- function( databaseSettings <- list( connectionDetailsSettings = connectionDetailsSettings, - schema = 'main', - tablePrefix = 'c_', - cohortTablePrefix = 'cg_', - incidenceTablePrefix = 'i_', - databaseTable = 'DATABASE_META_DATA' + schema = "main", + tablePrefix = "c_", + cohortTablePrefix = "cg_", + incidenceTablePrefix = "i_", + databaseTable = "DATABASE_META_DATA" ) return(databaseSettings) @@ -132,8 +129,7 @@ prepareCharacterizationShiny <- function( viewChars <- function( databaseSettings, - testApp = F - ){ + testApp = F) { ensure_installed("ShinyAppBuilder") ensure_installed("ResultModelManager") @@ -145,76 +141,70 @@ viewChars <- function( databaseSettings$connectionDetailsSettings <- NULL - if(utils::packageVersion('ShinyAppBuilder') < '1.2.0'){ - #use old method + if (utils::packageVersion("ShinyAppBuilder") < "1.2.0") { + # use old method # set database settings into system variables Sys.setenv("resultDatabaseDetails_characterization" = as.character(ParallelLogger::convertSettingsToJson(databaseSettings))) config <- ParallelLogger::loadSettingsFromJson( fileName = system.file( - 'shinyConfig.json', + "shinyConfig.json", package = "Characterization" ) ) - if(!testApp){ + if (!testApp) { ShinyAppBuilder::viewShiny( config = config, connection = connection ) - } else{ + } else { ShinyAppBuilder::createShinyApp(config = config, connection = connection) } - - } else{ + } else { # use new method config <- ParallelLogger::loadSettingsFromJson( fileName = system.file( - 'shinyConfigUpdate.json', + "shinyConfigUpdate.json", package = "Characterization" ) ) - databaseSettings$cTablePrefix = databaseSettings$tablePrefix - databaseSettings$cgTablePrefix = databaseSettings$cohortTablePrefix - databaseSettings$databaseTable = 'DATABASE_META_DATA' - databaseSettings$databaseTablePrefix = '' - databaseSettings$iTablePrefix = databaseSettings$incidenceTablePrefix + databaseSettings$cTablePrefix <- databaseSettings$tablePrefix + databaseSettings$cgTablePrefix <- databaseSettings$cohortTablePrefix + databaseSettings$databaseTable <- "DATABASE_META_DATA" + databaseSettings$databaseTablePrefix <- "" + databaseSettings$iTablePrefix <- databaseSettings$incidenceTablePrefix databaseSettings$cgTable <- "cohort_definition" - if(!testApp){ + if (!testApp) { ShinyAppBuilder::viewShiny( config = config, connection = connection, resultDatabaseSettings = databaseSettings ) - } else{ + } else { ShinyAppBuilder::createShinyApp( config = config, connection = connection, resultDatabaseSettings = databaseSettings - ) - + ) } - } - - } -getCohortNames <- function(cohortIds, cohortDefinitionSet){ - - if(!is.null(cohortDefinitionSet)){ - cohortNames <- sapply( - cohortIds, - function(x){ - cohortDefinitionSet$cohortName[cohortDefinitionSet$cohortId == x] - } - ) - } else{ - cohortNames <- paste0('cohort ', cohortIds) +getCohortNames <- function(cohortIds, cohortDefinitionSet) { + if (!is.null(cohortDefinitionSet)) { + cohortNames <- sapply( + cohortIds, + function(x) { + cohortDefinitionSet$cohortName[cohortDefinitionSet$cohortId == x] + } + ) + } else { + cohortNames <- paste0("cohort ", cohortIds) } return(cohortNames) @@ -222,9 +212,10 @@ getCohortNames <- function(cohortIds, cohortDefinitionSet){ # Borrowed from devtools: https://github.com/hadley/devtools/blob/ba7a5a4abd8258c52cb156e7b26bb4bf47a79f0b/R/utils.r#L44 -is_installed <- function (pkg, version = 0) { +is_installed <- function(pkg, version = 0) { installed_version <- tryCatch(utils::packageVersion(pkg), - error = function(e) NA) + error = function(e) NA + ) !is.na(installed_version) && installed_version >= version } @@ -235,17 +226,17 @@ ensure_installed <- function(pkg) { if (interactive()) { message(msg, "\nWould you like to install it?") if (utils::menu(c("Yes", "No")) == 1) { - if(pkg%in%c("ShinyAppBuilder", "ResultModelManager")){ - + if (pkg %in% c("ShinyAppBuilder", "ResultModelManager")) { # add code to check for devtools... - dvtCheck <- tryCatch(utils::packageVersion('devtools'), - error = function(e) NA) - if(is.na(dvtCheck)){ - utils::install.packages('devtools') + dvtCheck <- tryCatch(utils::packageVersion("devtools"), + error = function(e) NA + ) + if (is.na(dvtCheck)) { + utils::install.packages("devtools") } - devtools::install_github(paste0('OHDSI/',pkg)) - }else{ + devtools::install_github(paste0("OHDSI/", pkg)) + } else { utils::install.packages(pkg) } } else { diff --git a/docs/404.html b/docs/404.html index ac0bc8f..a8cd17d 100644 --- a/docs/404.html +++ b/docs/404.html @@ -32,7 +32,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/articles/InstallationGuide.html b/docs/articles/InstallationGuide.html index 1f631f2..9d0754e 100644 --- a/docs/articles/InstallationGuide.html +++ b/docs/articles/InstallationGuide.html @@ -33,7 +33,7 @@ Characterization - 0.1.1 + 0.1.5 @@ -96,7 +96,7 @@

Characterization Installation Guide

Jenna Reps

-

2023-03-15

+

2024-04-03

Source: vignettes/InstallationGuide.Rmd @@ -113,7 +113,7 @@

2023-03-15

Introduction

This vignette describes how you need to install the Observational -Health Data Sciencs and Informatics (OHDSI) Characterization +Health Data Sciences and Informatics (OHDSI) Characterization package under Windows, Mac, and Linux.

@@ -154,7 +154,7 @@

Installing the Packageremotes, which will automatically install the latest release and all the latest dependencies.

If you do not want the official release you could install the -bleading edge version of the package (latest develop branch).

+bleeding edge version of the package (latest develop branch).

Note that the latest develop branch could contain bugs, please report them to us if you experience problems.

diff --git a/docs/articles/UsingCharacterizationPackage.html b/docs/articles/UsingCharacterizationPackage.html index 6557e69..0086464 100644 --- a/docs/articles/UsingCharacterizationPackage.html +++ b/docs/articles/UsingCharacterizationPackage.html @@ -33,7 +33,7 @@ Characterization - 0.1.1 + 0.1.5

@@ -97,7 +97,7 @@

Using Characterization Package

Jenna Reps

-

2023-03-15

+

2024-04-03

Source: vignettes/UsingCharacterizationPackage.Rmd @@ -118,7 +118,7 @@

IntroductionIntroductionSetup connectionDetails <- Eunomia::getEunomiaConnectionDetails() Eunomia::createCohorts(connectionDetails = connectionDetails)
## Connecting using SQLite driver
-
## Creating cohort: Celecoxib
-## 
-  |                                                                            
-  |                                                                      |   0%
-  |                                                                            
-  |======================================================================| 100%
-
## Executing SQL took 0.00908 secs
-
## Creating cohort: Diclofenac
-## 
-  |                                                                            
-  |                                                                      |   0%
-  |                                                                            
-  |======================================================================| 100%
-
## Executing SQL took 0.00446 secs
-
## Creating cohort: GiBleed
-## 
-  |                                                                            
-  |                                                                      |   0%
-  |                                                                            
-  |======================================================================| 100%
-
## Executing SQL took 0.00896 secs
-
## Creating cohort: NSAIDs
-## 
-  |                                                                            
-  |                                                                      |   0%
-  |                                                                            
-  |======================================================================| 100%
-
## Executing SQL took 0.0542 secs
+
## Creating cohort: Celecoxib
+##   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
+
## Executing SQL took 0.0152 secs
+
## Creating cohort: Diclofenac
+##   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
+
## Executing SQL took 0.0169 secs
+
## Creating cohort: GiBleed
+##   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
+
## Executing SQL took 0.0208 secs
+
## Creating cohort: NSAIDs
+##   |                                                                              |                                                                      |   0%  |                                                                              |======================================================================| 100%
+
## Executing SQL took 0.0579 secs
## Cohorts created in table main.cohort
##   cohortId       name
 ## 1        1  Celecoxib
@@ -247,47 +231,47 @@ 

Aggreagate Covariates
-  exampleTargetIds <- c(1,2,4)
-  exampleOutcomeIds <- 3
+exampleTargetIds <- c(1, 2, 4) +exampleOutcomeIds <- 3

If we want to get information on the sex assigned at birth, age at index and Charlson Comorbidity index we can create the settings using FeatureExtraction::createCovariateSettings:

-  exampleCovariateSettings <- FeatureExtraction::createCovariateSettings(
-    useDemographicsGender = T,
-    useDemographicsAge = T,
-    useCharlsonIndex = T
-    )
+exampleCovariateSettings <- FeatureExtraction::createCovariateSettings( + useDemographicsGender = T, + useDemographicsAge = T, + useCharlsonIndex = T +)

If we want to create the aggregate features for all our target cohorts, our outcome cohort and each target cohort restricted to those with a record of the outcome 1 day after target cohort start date until 365 days after target cohort end date we can run:

-  exampleAggregateCovariateSettings <- createAggregateCovariateSettings(
-    targetIds = exampleTargetIds,
-    outcomeIds = exampleOutcomeIds,
-    riskWindowStart = 1, startAnchor = 'cohort start',
-    riskWindowEnd = 365, endAnchor = 'cohort start',
-    covariateSettings = exampleCovariateSettings
-    )
+exampleAggregateCovariateSettings <- createAggregateCovariateSettings( + targetIds = exampleTargetIds, + outcomeIds = exampleOutcomeIds, + riskWindowStart = 1, startAnchor = "cohort start", + riskWindowEnd = 365, endAnchor = "cohort start", + covariateSettings = exampleCovariateSettings +)

Next we need to use the exampleAggregateCovariateSettings as the settings to computeAggregateCovariateAnalyses, we need to use the Eunomia connectionDetails and in Eunomia the OMOP CDM data and cohort table are in the ‘main’ schema. The cohort table name is ‘cohort’. The -following code will apply the aggregative covariates analysis using the +following code will apply the aggregated covariates analysis using the previously specified settings on the simulated Eunomia data:

 agc <- computeAggregateCovariateAnalyses(
-    connectionDetails = connectionDetails,
-    cdmDatabaseSchema = 'main',
-    cdmVersion = 5,
-    targetDatabaseSchema = 'main',
-    targetTable = 'cohort',
-    aggregateCovariateSettings = exampleAggregateCovariateSettings,
-    databaseId = 'Eunomia', 
-    runId = 1
-    )
+ connectionDetails = connectionDetails, + cdmDatabaseSchema = "main", + cdmVersion = 5, + targetDatabaseSchema = "main", + targetTable = "cohort", + aggregateCovariateSettings = exampleAggregateCovariateSettings, + databaseId = "Eunomia", + runId = 1 +)

If you would like to save the results you can use the function saveAggregateCovariateAnalyses and this can then be loaded using loadAggregateCovariateAnalyses.

@@ -297,11 +281,9 @@

Aggreagate Covariatescovariates:
-agc$covariates %>% 
+agc$covariates %>%
   collect() %>%
-  kableExtra::kbl() 
-
## Warning in !is.null(rmarkdown::metadata$output) && rmarkdown::metadata$output
-## %in% : 'length(x) = 3 > 1' in coercion to 'logical(1)'
+ kableExtra::kbl()
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
@@ -738,126 +720,6 @@

Aggreagate Covariates

-714 - -0.4941176 -
-Eunomia - -1 - -11 - -8532001 - -731 - -0.5058824 -
-Eunomia - -1 - -12 - -8507001 - -338 - -0.4787535 -
-Eunomia - -1 - -12 - -8532001 - -368 - -0.5212465 -
-Eunomia - -1 - -13 - -8507001 - -1052 - -0.4890748 -
-Eunomia - -1 - -13 - -8532001 - -1099 - -0.5109252 -
-Eunomia - -1 - -14 - -8507001 - 180 @@ -872,7 +734,7 @@

Aggreagate Covariates

-14 +11 8532001 @@ -892,7 +754,7 @@

Aggreagate Covariates

-15 +12 8507001 @@ -912,7 +774,7 @@

Aggreagate Covariates

-15 +12 8532001 @@ -932,7 +794,7 @@

Aggreagate Covariates

-16 +13 8507001 @@ -952,7 +814,7 @@

Aggreagate Covariates

-16 +13 8532001 @@ -972,127 +834,7 @@

Aggreagate Covariates

-17 - -8507001 - -714 - -0.4941176 -
-Eunomia - -1 - -17 - -8532001 - -731 - -0.5058824 -
-Eunomia - -1 - -18 - -8507001 - -338 - -0.4787535 -
-Eunomia - -1 - -18 - -8532001 - -368 - -0.5212465 -
-Eunomia - -1 - -19 - -8507001 - -1052 - -0.4890748 -
-Eunomia - -1 - -19 - -8532001 - -1099 - -0.5109252 -
-Eunomia - -1 - -20 +14 8507001 @@ -1112,7 +854,7 @@

Aggreagate Covariates

-20 +14 8532001 @@ -1132,7 +874,7 @@

Aggreagate Covariates

-21 +15 8507001 @@ -1152,7 +894,7 @@

Aggreagate Covariates

-21 +15 8532001 @@ -1172,7 +914,7 @@

Aggreagate Covariates

-22 +16 8507001 @@ -1192,7 +934,7 @@

Aggreagate Covariates

-22 +16 8532001 @@ -1212,7 +954,7 @@

Aggreagate Covariates

-23 +17 8507001 @@ -1232,7 +974,7 @@

Aggreagate Covariates

-23 +17 8532001 @@ -1252,7 +994,7 @@

Aggreagate Covariates

-24 +18 8507001 @@ -1272,7 +1014,7 @@

Aggreagate Covariates

-24 +18 8532001 @@ -1292,7 +1034,7 @@

Aggreagate Covariates

-25 +19 8507001 @@ -1312,7 +1054,7 @@

Aggreagate Covariates

-25 +19 8532001 @@ -1332,7 +1074,7 @@

Aggreagate Covariates

-26 +20 8507001 @@ -1352,7 +1094,7 @@

Aggreagate Covariates

-26 +20 8532001 @@ -1369,10 +1111,10 @@

Aggreagate Covariates
  • covariatesContinuous:
  • -
    -agc$covariatesContinuous %>% 
    +
    +agc$covariatesContinuous %>%
       collect() %>%
    -  kableExtra::kbl() 
    + kableExtra::kbl()
    - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -2791,40 +2005,40 @@

    Aggreagate Covariates

    @@ -2835,13 +2049,13 @@

    Aggreagate Covariates

    @@ -2879,13 +2093,13 @@

    Aggreagate Covariates

    @@ -2923,25 +2137,25 @@

    Aggreagate Covariates

    @@ -3055,25 +2269,25 @@

    Aggreagate Covariates

    @@ -3099,25 +2313,25 @@

    Aggreagate Covariates

    @@ -3143,25 +2357,25 @@

    Aggreagate Covariates

    @@ -3187,28 +2401,28 @@

    Aggreagate Covariates

    @@ -3231,28 +2445,28 @@

    Aggreagate Covariates

    @@ -3275,31 +2489,31 @@

    Aggreagate Covariates

    @@ -3319,31 +2533,31 @@

    Aggreagate Covariates

    @@ -3363,31 +2577,31 @@

    Aggreagate Covariates

    @@ -3407,31 +2621,31 @@

    Aggreagate Covariates

    @@ -3451,25 +2665,25 @@

    Aggreagate Covariates

    @@ -1515,7 +1257,7 @@

    Aggreagate Covariates

    -15 +12 1901 @@ -1559,7 +1301,7 @@

    Aggreagate Covariates

    -25 +19 1901 @@ -1603,110 +1345,22 @@

    Aggreagate Covariates

    -12 +8 1901 -255 +275 0 -3 +2 -0.3980170 - -0.3159103 - -0 - -0 - -0 - -1 - -1 -
    -Eunomia - -1 - -18 - -1901 - -255 - -0 - -3 - -0.3980170 - -0.3159103 - -0 - -0 - -0 - -1 - -1 -
    -Eunomia - -1 - -8 - -1901 - -275 - -0 - -2 - -0.9549296 +0.9549296 0.4233403 @@ -1735,7 +1389,7 @@

    Aggreagate Covariates

    -14 +11 1901 @@ -1823,7 +1477,7 @@

    Aggreagate Covariates

    -24 +18 1901 @@ -1911,7 +1565,7 @@

    Aggreagate Covariates

    -21 +15 1901 @@ -1999,7 +1653,7 @@

    Aggreagate Covariates

    -16 +13 1901 @@ -2131,7 +1785,7 @@

    Aggreagate Covariates

    -23 +17 1901 @@ -2175,7 +1829,7 @@

    Aggreagate Covariates

    -26 +20 1901 @@ -2219,57 +1873,13 @@

    Aggreagate Covariates

    -11 - -1901 - -660 - -0 - -2 - -0.5307958 - -0.3688415 - -0 - -0 - -0 - -1 - -1 -
    -Eunomia - -1 - -17 +5 1901 -660 +935 0 @@ -2278,103 +1888,15 @@

    Aggreagate Covariates

    -0.5307958 - -0.3688415 - -0 - -0 - -0 - -1 - -1 -
    -Eunomia - -1 - -13 - -1901 - -915 - -0 - -3 - -0.4872152 - -0.3557403 - -0 - -0 - -0 - -1 +0.6144444 -1 -
    -Eunomia +0.3867813 1 -19 - -1901 - -915 - -0 - -3 - -0.4872152 - -0.3557403 - -0 - 0 @@ -2395,13 +1917,13 @@

    Aggreagate Covariates

    -5 +14 1901 -935 +958 0 @@ -2410,10 +1932,10 @@

    Aggreagate Covariates

    -0.6144444 +0.6144252 -0.3867813 +0.3865994 1 @@ -2439,348 +1961,40 @@

    Aggreagate Covariates

    -20 +7 1901 -958 - -0 - -2 - -0.6144252 - -0.3865994 - -1 - -0 +1231 0 -1 - -1 -
    -Eunomia - -1 - -7 - -1901 - -1231 - -0 - -3 +3 0.5475285 -0.3777510 - -0 - -0 - -0 - -1 - -1 -
    -Eunomia - -1 - -22 - -1901 - -1262 - -0 - -3 - -0.5478842 - -0.3775118 - -0 - -0 - -0 - -1 - -1 -
    -Eunomia - -1 - -9 - -1002 - -124 - -32 - -46 - -38.8709677 - -3.4000663 - -39 - -34 - -36 - -41 - -44 -
    -Eunomia - -1 - -15 - -1002 - -124 - -32 - -46 - -38.8709677 - -3.4000663 - -39 - -34 - -36 - -41 - -44 -
    -Eunomia - -1 - -3 - -1002 - -124 - -32 - -47 - -38.9758065 - -3.4226973 - -39 - -34 - -36 - -41 - -44 -
    -Eunomia - -1 - -25 - -1002 - -124 - -32 - -47 - -38.9758065 - -3.4226973 - -39 - -34 - -36 - -41 - -44 -
    -Eunomia - -1 - -8 - -1002 - -355 - -32 - -46 - -38.7746479 - -3.2746121 +0.3777510 -39 +0 -35 +0 -36 +0 -41 +1 -43 +1
    -14 +16 -1002 +1901 -355 +1262 -32 +0 -46 +3 -38.7746479 +0.5478842 -3.2746121 +0.3775118 -39 +0 -35 +0 -36 +0 -41 +1 -43 +1
    -2 +9 1002 -355 +124 32 @@ -2850,16 +2064,16 @@

    Aggreagate Covariates

    -38.9014085 +38.8709677 -3.2449654 +3.4000663 39 -35 +34 36 @@ -2868,7 +2082,7 @@

    Aggreagate Covariates

    -43 +44
    -24 +12 1002 -355 +124 32 @@ -2894,16 +2108,16 @@

    Aggreagate Covariates

    -38.9014085 +38.8709677 -3.2449654 +3.4000663 39 -35 +34 36 @@ -2912,7 +2126,7 @@

    Aggreagate Covariates

    -43 +44
    -10 +3 1002 -479 +124 32 -46 +47 -38.7995825 +38.9758065 -3.3042257 +3.4226973 39 @@ -2967,25 +2181,25 @@

    Aggreagate Covariates

    -16 +19 1002 -479 +124 32 -46 +47 -38.7995825 +38.9758065 -3.3042257 +3.4226973 39 @@ -3011,25 +2225,25 @@

    Aggreagate Covariates

    -1 +8 1002 -479 +355 32 -47 +46 -38.9206681 +38.7746479 -3.2884308 +3.2746121 39 @@ -3044,7 +2258,7 @@

    Aggreagate Covariates

    -44 +43
    -4 +11 1002 -479 +355 32 -47 +46 -38.9206681 +38.7746479 -3.2884308 +3.2746121 39 @@ -3088,7 +2302,7 @@

    Aggreagate Covariates

    -44 +43
    -23 +2 1002 -479 +355 32 -47 +46 -38.9206681 +38.9014085 -3.2884308 +3.2449654 39 @@ -3132,7 +2346,7 @@

    Aggreagate Covariates

    -44 +43
    -26 +18 1002 -479 +355 32 -47 +46 -38.9206681 +38.9014085 -3.2884308 +3.2449654 39 @@ -3176,7 +2390,7 @@

    Aggreagate Covariates

    -44 +43
    -12 +10 1002 -706 +479 -31 +32 46 -38.5226629 +38.7995825 -3.2712236 +3.3042257 -38 +39 34 @@ -3220,7 +2434,7 @@

    Aggreagate Covariates

    -43 +44
    -18 +13 1002 -706 +479 -31 +32 46 -38.5226629 +38.7995825 -3.2712236 +3.3042257 -38 +39 34 @@ -3264,7 +2478,7 @@

    Aggreagate Covariates

    -43 +44
    -6 +1 1002 -830 +479 -31 +32 -46 +47 -38.5746988 +38.9206681 -3.2910429 +3.2884308 39 -34 +35 36 @@ -3308,7 +2522,7 @@

    Aggreagate Covariates

    -43 +44
    -21 +4 1002 -850 +479 -31 +32 -46 +47 -38.5658824 +38.9206681 -3.2816028 +3.2884308 39 -34 +35 36 @@ -3352,7 +2566,7 @@

    Aggreagate Covariates

    -43 +44
    -11 +17 1002 -1445 +479 -31 +32 47 -38.6131488 +38.9206681 -3.3329496 +3.2884308 39 -34 +35 36 @@ -3396,7 +2610,7 @@

    Aggreagate Covariates

    -43 +44
    -17 +20 1002 -1445 +479 -31 +32 47 -38.6131488 +38.9206681 -3.3329496 +3.2884308 39 -34 +35 36 @@ -3440,7 +2654,7 @@

    Aggreagate Covariates

    -43 +44
    -5 +6 1002 -1800 +830 31 -47 +46 -38.6450000 +38.5746988 -3.3212435 +3.2910429 39 @@ -3495,25 +2709,25 @@

    Aggreagate Covariates

    -20 +15 1002 -1844 +850 31 -47 +46 -38.6469631 +38.5658824 -3.3192555 +3.2816028 39 @@ -3539,13 +2753,13 @@

    Aggreagate Covariates

    -13 +5 1002 -2151 +1800 31 @@ -3554,10 +2768,10 @@

    Aggreagate Covariates

    -38.5834496 +38.6450000 -3.3123287 +3.3212435 39 @@ -3583,13 +2797,13 @@

    Aggreagate Covariates

    -19 +14 1002 -2151 +1844 31 @@ -3598,10 +2812,10 @@

    Aggreagate Covariates

    -38.5834496 +38.6469631 -3.3123287 +3.3192555 39 @@ -3671,7 +2885,7 @@

    Aggreagate Covariates

    -22 +16 1002 @@ -3712,10 +2926,10 @@

    Aggreagate Covariates
  • covariateRef:
  • -
    -agc$covariateRef %>% 
    +
    +agc$covariateRef %>%
       collect() %>%
    -  kableExtra::kbl() 
    + kableExtra::kbl()
    @@ -3823,10 +3037,10 @@

    Aggreagate Covariates
  • analysisRef:
  • -
    -agc$analysisRef %>% 
    +
    +agc$analysisRef %>%
       collect() %>%
    -  kableExtra::kbl() 
    + kableExtra::kbl()
    @@ -3965,60 +3179,46 @@

    Dechallenge RechallengeUsing the Eunomia data were we previous generated four cohorts, we can use cohort ids 1,2 and 4 as the targetIds and cohort id 3 as the outcomeIds:

    -
    -  exampleTargetIds <- c(1,2,4)
    -  exampleOutcomeIds <- 3
    +
    +exampleTargetIds <- c(1, 2, 4)
    +exampleOutcomeIds <- 3

    If we want to create the dechallenge rechallenge for all our target cohorts and our outcome cohort with a 30 day dechallengeStopInterval and 31 day dechallengeEvaluationWindow:

    -
    -  exampleDechallengeRechallengeSettings <- createDechallengeRechallengeSettings(
    -    targetIds = exampleTargetIds,
    -    outcomeIds = exampleOutcomeIds,
    -    dechallengeStopInterval = 30,
    -    dechallengeEvaluationWindow = 31
    -    )
    +
    +exampleDechallengeRechallengeSettings <- createDechallengeRechallengeSettings(
    +  targetIds = exampleTargetIds,
    +  outcomeIds = exampleOutcomeIds,
    +  dechallengeStopInterval = 30,
    +  dechallengeEvaluationWindow = 31
    +)

    We can then run the analysis on the Eunomia data using computeDechallengeRechallengeAnalyses and the settings previously specified:

    -
    +
     dc <- computeDechallengeRechallengeAnalyses(
    -    connectionDetails = connectionDetails,
    -    targetDatabaseSchema = 'main',
    -    targetTable = 'cohort',
    -    dechallengeRechallengeSettings = exampleDechallengeRechallengeSettings,
    -    databaseId = 'Eunomia'
    -    )
    + connectionDetails = connectionDetails, + targetDatabaseSchema = "main", + targetTable = "cohort", + dechallengeRechallengeSettings = exampleDechallengeRechallengeSettings, + databaseId = "Eunomia" +)
    ## Inputs checked
    ## Connecting using SQLite driver
     ## Computing dechallenge rechallenge results
    -
    ## 
    -  |                                                                            
    -  |                                                                      |   0%
    -  |                                                                            
    -  |============                                                          |  17%
    -  |                                                                            
    -  |=======================                                               |  33%
    -  |                                                                            
    -  |===================================                                   |  50%
    -  |                                                                            
    -  |===============================================                       |  67%
    -  |                                                                            
    -  |==========================================================            |  83%
    -  |                                                                            
    -  |======================================================================| 100%
    -
    ## Executing SQL took 0.00792 secs
    -## Computing dechallenge rechallenge for 3 target ids and 1outcome ids took 0.0625 secs
    +
    ##   |                                                                              |                                                                      |   0%  |                                                                              |============                                                          |  17%  |                                                                              |=======================                                               |  33%  |                                                                              |===================================                                   |  50%  |                                                                              |===============================================                       |  67%  |                                                                              |==========================================================            |  83%  |                                                                              |======================================================================| 100%
    +
    ## Executing SQL took 0.00758 secs
    +## Computing dechallenge rechallenge for 3 target ids and 1outcome ids took 0.165 secs

    If you would like to save the results you can use the function saveDechallengeRechallengeAnalyses and this can then be loaded using loadDechallengeRechallengeAnalyses.

    The results are Andromeda objects that can we viewed using dplyr. There is just one table named dechallengeRechallenge:

    -
    -dc$dechallengeRechallenge %>% 
    +
    +dc$dechallengeRechallenge %>%
       collect() %>%
    -  kableExtra::kbl() 
    + kableExtra::kbl()
    @@ -4086,43 +3286,29 @@

    Dechallenge Rechallenge

    Next it is possible to computer and extract the failed rechallenge cases

    -
    +
     failed <- computeRechallengeFailCaseSeriesAnalyses(
       connectionDetails = connectionDetails,
    -  targetDatabaseSchema = 'main',
    -  targetTable = 'cohort',
    +  targetDatabaseSchema = "main",
    +  targetTable = "cohort",
       dechallengeRechallengeSettings = exampleDechallengeRechallengeSettings,
    -  outcomeDatabaseSchema = 'main',
    -  outcomeTable = 'cohort',
    -  databaseId = 'Eunomia'
    +  outcomeDatabaseSchema = "main",
    +  outcomeTable = "cohort",
    +  databaseId = "Eunomia"
     )
    ## Inputs checked
    ## Connecting using SQLite driver
     ## Computing dechallenge rechallenge results
    -
    ## 
    -  |                                                                            
    -  |                                                                      |   0%
    -  |                                                                            
    -  |============                                                          |  17%
    -  |                                                                            
    -  |=======================                                               |  33%
    -  |                                                                            
    -  |===================================                                   |  50%
    -  |                                                                            
    -  |===============================================                       |  67%
    -  |                                                                            
    -  |==========================================================            |  83%
    -  |                                                                            
    -  |======================================================================| 100%
    -
    ## Executing SQL took 0.0925 secs
    -## Computing dechallenge failed case series for 3 target IDs and 1 outcome IDs took 0.133 secs
    +
    ##   |                                                                              |                                                                      |   0%  |                                                                              |============                                                          |  17%  |                                                                              |=======================                                               |  33%  |                                                                              |===================================                                   |  50%  |                                                                              |===============================================                       |  67%  |                                                                              |==========================================================            |  83%  |                                                                              |======================================================================| 100%
    +
    ## Executing SQL took 0.0748 secs
    +## Computing dechallenge failed case series for 3 target IDs and 1 outcome IDs took 0.219 secs

    The results are Andromeda objects that can we viewed using dplyr. There is just one table named rechallengeFailCaseSeries:

    -
    -failed$rechallengeFailCaseSeries %>% 
    +
    +failed$rechallengeFailCaseSeries %>%
       collect() %>%
    -  kableExtra::kbl() 
    + kableExtra::kbl()
    @@ -4192,75 +3378,41 @@

    Time to Event
    -  exampleTimeToEventSettings <- createTimeToEventSettings(
    -    targetIds = exampleTargetIds,
    -    outcomeIds = exampleOutcomeIds
    -    )
    +
    +exampleTimeToEventSettings <- createTimeToEventSettings(
    +  targetIds = exampleTargetIds,
    +  outcomeIds = exampleOutcomeIds
    +)

    We can then run the analysis on the Eunomia data using computeTimeToEventAnalyses and the settings previously specified:

    -
    +
     tte <- computeTimeToEventAnalyses(
    -    connectionDetails = connectionDetails,
    -    cdmDatabaseSchema = 'main',
    -    targetDatabaseSchema = 'main',
    -    targetTable = 'cohort', 
    -    timeToEventSettings =  exampleTimeToEventSettings,
    -    databaseId = 'Eunomia'
    -    )
    + connectionDetails = connectionDetails, + cdmDatabaseSchema = "main", + targetDatabaseSchema = "main", + targetTable = "cohort", + timeToEventSettings = exampleTimeToEventSettings, + databaseId = "Eunomia" +)
    ## Connecting using SQLite driver
     ## Uploading #cohort_settings
     ## 
    -## Inserting data took 0.0043 secs
    +## Inserting data took 0.00654 secs
     ## Computing time to event results
    -
    ## 
    -  |                                                                            
    -  |                                                                      |   0%
    -  |                                                                            
    -  |====                                                                  |   6%
    -  |                                                                            
    -  |=========                                                             |  12%
    -  |                                                                            
    -  |=============                                                         |  19%
    -  |                                                                            
    -  |==================                                                    |  25%
    -  |                                                                            
    -  |======================                                                |  31%
    -  |                                                                            
    -  |==========================                                            |  38%
    -  |                                                                            
    -  |===============================                                       |  44%
    -  |                                                                            
    -  |===================================                                   |  50%
    -  |                                                                            
    -  |=======================================                               |  56%
    -  |                                                                            
    -  |============================================                          |  62%
    -  |                                                                            
    -  |================================================                      |  69%
    -  |                                                                            
    -  |====================================================                  |  75%
    -  |                                                                            
    -  |=========================================================             |  81%
    -  |                                                                            
    -  |=============================================================         |  88%
    -  |                                                                            
    -  |==================================================================    |  94%
    -  |                                                                            
    -  |======================================================================| 100%
    -
    ## Executing SQL took 0.0418 secs
    -## Computing time-to-event for T-O pairs took 0.145 secs
    +
    ##   |                                                                              |                                                                      |   0%  |                                                                              |===                                                                   |   4%  |                                                                              |======                                                                |   8%  |                                                                              |=========                                                             |  12%  |                                                                              |============                                                          |  17%  |                                                                              |===============                                                       |  21%  |                                                                              |==================                                                    |  25%  |                                                                              |====================                                                  |  29%  |                                                                              |=======================                                               |  33%  |                                                                              |==========================                                            |  38%  |                                                                              |=============================                                         |  42%  |                                                                              |================================                                      |  46%  |                                                                              |===================================                                   |  50%  |                                                                              |======================================                                |  54%  |                                                                              |=========================================                             |  58%  |                                                                              |============================================                          |  62%  |                                                                              |===============================================                       |  67%  |                                                                              |==================================================                    |  71%  |                                                                              |====================================================                  |  75%  |                                                                              |=======================================================               |  79%  |                                                                              |==========================================================            |  83%  |                                                                              |=============================================================         |  88%  |                                                                              |================================================================      |  92%  |                                                                              |===================================================================   |  96%  |                                                                              |======================================================================| 100%
    +
    ## Executing SQL took 0.0462 secs
    +## Computing time-to-event for T-O pairs took 0.268 secs

    If you would like to save the results you can use the function saveTimeToEventAnalyses and this can then be loaded using loadTimeToEventAnalyses.

    The results are Andromeda objects that can we viewed using dplyr. There is just one table named timeToEvent:

    -
    -tte$timeToEvent %>% 
    +
    +tte$timeToEvent %>%
       collect() %>%
       top_n(10) %>%
    -  kableExtra::kbl() 
    + kableExtra::kbl()
    ## Selecting by timeScale
    @@ -4613,56 +3765,56 @@

    Run Multiple
    -  characterizationSettings <- createCharacterizationSettings(
    -    timeToEventSettings = list(
    -      exampleTimeToEventSettings
    -      ),
    -    dechallengeRechallengeSettings = list(
    -      exampleDechallengeRechallengeSettings
    -    ),
    -    aggregateCovariateSettings = list(
    -      exampleAggregateCovariateSettings
    -      )
    +
    +characterizationSettings <- createCharacterizationSettings(
    +  timeToEventSettings = list(
    +    exampleTimeToEventSettings
    +  ),
    +  dechallengeRechallengeSettings = list(
    +    exampleDechallengeRechallengeSettings
    +  ),
    +  aggregateCovariateSettings = list(
    +    exampleAggregateCovariateSettings
       )
    +)
     
     # save the settings using
     saveCharacterizationSettings(
    -  settings = characterizationSettings, 
    -  saveDirectory = file.path(tempdir(), 'saveSettings')
    -    )
    +  settings = characterizationSettings,
    +  saveDirectory = file.path(tempdir(), "saveSettings")
    +)
     
     # the settings can be loaded
     characterizationSettings <- loadCharacterizationSettings(
    -  saveDirectory = file.path(tempdir(), 'saveSettings')
    -    )
    +  saveDirectory = file.path(tempdir(), "saveSettings")
    +)
     
     runCharacterizationAnalyses(
       connectionDetails = connectionDetails,
    -  cdmDatabaseSchema = 'main',
    -  targetDatabaseSchema = 'main',
    -  targetTable = 'cohort',
    -  outcomeDatabaseSchema = 'main',
    -  outcomeTable = 'cohort',
    +  cdmDatabaseSchema = "main",
    +  targetDatabaseSchema = "main",
    +  targetTable = "cohort",
    +  outcomeDatabaseSchema = "main",
    +  outcomeTable = "cohort",
       characterizationSettings = characterizationSettings,
    -  saveDirectory = file.path(tempdir(), 'example'),
    -  tablePrefix = 'c_',
    -  databaseId = '1'
    +  saveDirectory = file.path(tempdir(), "example"),
    +  tablePrefix = "c_",
    +  databaseId = "1"
     )

    This will create an SQLITE database with all the analyses saved into the saveDirectory. You can export the results as csv files using:

    -
    +
     connectionDetailsT <- DatabaseConnector::createConnectionDetails(
    -  dbms = 'sqlite',
    -  server = file.path(tempdir(),'example','sqliteCharacterization', 'sqlite.sqlite')
    +  dbms = "sqlite",
    +  server = file.path(tempdir(), "example", "sqliteCharacterization", "sqlite.sqlite")
     )
     
     exportDatabaseToCsv(
       connectionDetails = connectionDetailsT,
    -  resultSchema = 'main',
    -  targetDialect = 'sqlite',
    -  tablePrefix = 'c_',
    -  saveDirectory = file.path(tempdir(),'csv')
    +  resultSchema = "main",
    +  targetDialect = "sqlite",
    +  tablePrefix = "c_",
    +  saveDirectory = file.path(tempdir(), "csv")
     )
    diff --git a/docs/articles/index.html b/docs/articles/index.html index e50dfae..4e375e9 100644 --- a/docs/articles/index.html +++ b/docs/articles/index.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/authors.html b/docs/authors.html index 9dfa84f..930b70d 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 @@ -90,14 +90,14 @@

    Citation

    -

    Reps J, Ryan P (2023). +

    Reps J, Ryan P (2024). Characterization: Characterizations of Cohorts. https://ohdsi.github.io/Characterization, https://github.com/OHDSI/Characterization.

    @Manual{,
       title = {Characterization: Characterizations of Cohorts},
       author = {Jenna Reps and Patrick Ryan},
    -  year = {2023},
    +  year = {2024},
       note = {https://ohdsi.github.io/Characterization, https://github.com/OHDSI/Characterization},
     }
    diff --git a/docs/index.html b/docs/index.html index 1f63a1c..13d8406 100644 --- a/docs/index.html +++ b/docs/index.html @@ -33,7 +33,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/news/index.html b/docs/news/index.html index 2dddd1d..b82f989 100644 --- a/docs/news/index.html +++ b/docs/news/index.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 @@ -72,13 +72,29 @@

    Changelog

    Source: NEWS.md +
    + +

    Changed export to csv approach to use batch export from SQLite (#41)

    +
    +
    + +

    Added extra error logging

    +
    +
    + +

    Optimized aggregate features to remove T and not Os (as these can be calculated using T and T and Os) - requires latest shiny app though Optimized database extraction to csv

    +
    +
    + +

    Fixing bug where first outcome was still all outcomes Updating shiny app to work with old and new ShinyAppBuilder

    +

    Fixing bug where cohort_counts were not being saved in the database

    -
    • added support to enable target cohorts with multiple cohort entries for the aggregate covariate analysis by restructing to first cohort entry and ensuring the subject has a user specified minPriorObservation days observation in the database at first entry and also perform analysis on first outcomes and any outcome that is recorded during TAR.
    • +
      • added support to enable target cohorts with multiple cohort entries for the aggregate covariate analysis by restricting to first cohort entry and ensuring the subject has a user specified minPriorObservation days observation in the database at first entry and also perform analysis on first outcomes and any outcome that is recorded during TAR.
      • added shiny app
    diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 036bdeb..c233713 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,8 +1,8 @@ -pandoc: 2.19.2 +pandoc: 3.1.1 pkgdown: 2.0.7 pkgdown_sha: ~ articles: InstallationGuide: InstallationGuide.html UsingCharacterizationPackage: UsingCharacterizationPackage.html -last_built: 2023-03-16T00:54Z +last_built: 2024-04-03T18:44Z diff --git a/docs/pull_request_template.html b/docs/pull_request_template.html index 9233960..3935c1f 100644 --- a/docs/pull_request_template.html +++ b/docs/pull_request_template.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5
    diff --git a/docs/reference/Characterization-package.html b/docs/reference/Characterization-package.html index 1d1611e..3666700 100644 --- a/docs/reference/Characterization-package.html +++ b/docs/reference/Characterization-package.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/computeAggregateCovariateAnalyses.html b/docs/reference/computeAggregateCovariateAnalyses.html index 085e4f9..dec7ad9 100644 --- a/docs/reference/computeAggregateCovariateAnalyses.html +++ b/docs/reference/computeAggregateCovariateAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/computeDechallengeRechallengeAnalyses.html b/docs/reference/computeDechallengeRechallengeAnalyses.html index 311f42c..052b108 100644 --- a/docs/reference/computeDechallengeRechallengeAnalyses.html +++ b/docs/reference/computeDechallengeRechallengeAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/computeRechallengeFailCaseSeriesAnalyses.html b/docs/reference/computeRechallengeFailCaseSeriesAnalyses.html index 35496ff..201027e 100644 --- a/docs/reference/computeRechallengeFailCaseSeriesAnalyses.html +++ b/docs/reference/computeRechallengeFailCaseSeriesAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/computeTimeToEventAnalyses.html b/docs/reference/computeTimeToEventAnalyses.html index ff0d09d..f34a698 100644 --- a/docs/reference/computeTimeToEventAnalyses.html +++ b/docs/reference/computeTimeToEventAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/createAggregateCovariateSettings.html b/docs/reference/createAggregateCovariateSettings.html index 3765fc4..dd26870 100644 --- a/docs/reference/createAggregateCovariateSettings.html +++ b/docs/reference/createAggregateCovariateSettings.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/createCharacterizationSettings.html b/docs/reference/createCharacterizationSettings.html index 755fbf0..f02ea35 100644 --- a/docs/reference/createCharacterizationSettings.html +++ b/docs/reference/createCharacterizationSettings.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/createCharacterizationTables.html b/docs/reference/createCharacterizationTables.html index e3bef67..409a2cc 100644 --- a/docs/reference/createCharacterizationTables.html +++ b/docs/reference/createCharacterizationTables.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/createDechallengeRechallengeSettings.html b/docs/reference/createDechallengeRechallengeSettings.html index ea36615..4361238 100644 --- a/docs/reference/createDechallengeRechallengeSettings.html +++ b/docs/reference/createDechallengeRechallengeSettings.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/createSqliteDatabase.html b/docs/reference/createSqliteDatabase.html index 70750dc..f553e0c 100644 --- a/docs/reference/createSqliteDatabase.html +++ b/docs/reference/createSqliteDatabase.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/createTimeToEventSettings.html b/docs/reference/createTimeToEventSettings.html index d1a87c1..c44d96d 100644 --- a/docs/reference/createTimeToEventSettings.html +++ b/docs/reference/createTimeToEventSettings.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/exportAggregateCovariateToCsv.html b/docs/reference/exportAggregateCovariateToCsv.html index 1e1d94e..7b834e1 100644 --- a/docs/reference/exportAggregateCovariateToCsv.html +++ b/docs/reference/exportAggregateCovariateToCsv.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 @@ -78,7 +78,7 @@

    export the AggregateCovariate results as csv

    -
    exportAggregateCovariateToCsv(result, saveDirectory)
    +
    exportAggregateCovariateToCsv(result, saveDirectory, minCellCount = 0)
    @@ -90,6 +90,10 @@

    Arguments

    saveDirectory

    An directory location to save the results into

    + +
    minCellCount
    +

    The minimum value that will be displayed in count columns

    +

    Value

    diff --git a/docs/reference/exportDatabaseToCsv.html b/docs/reference/exportDatabaseToCsv.html index e1b473d..421d14a 100644 --- a/docs/reference/exportDatabaseToCsv.html +++ b/docs/reference/exportDatabaseToCsv.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5
    @@ -81,11 +81,12 @@

    Exports all tables in the result database to csv files

    exportDatabaseToCsv(
       connectionDetails,
       resultSchema,
    -  targetDialect,
    +  targetDialect = NULL,
       tablePrefix = "c_",
       filePrefix = NULL,
    -  tempEmulationSchema = NULL,
    -  saveDirectory
    +  tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"),
    +  saveDirectory,
    +  minMeanCovariateValue = 0.001
     )
    @@ -102,7 +103,7 @@

    Arguments

    targetDialect
    -

    The database management system being used

    +

    DEPRECATED: derived from connectionDetails.

    tablePrefix
    @@ -120,6 +121,12 @@

    Arguments

    saveDirectory

    The directory to save the csv results

    + +
    minMeanCovariateValue
    +

    The minimum mean covariate value (i.e. the minimum proportion for +binary covariates) for a covariate to be included in covariate table. +Other covariates are removed to save space.

    +

    Value

    diff --git a/docs/reference/exportDechallengeRechallengeToCsv.html b/docs/reference/exportDechallengeRechallengeToCsv.html index 7411746..98f69f4 100644 --- a/docs/reference/exportDechallengeRechallengeToCsv.html +++ b/docs/reference/exportDechallengeRechallengeToCsv.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5
    @@ -78,7 +78,7 @@

    export the DechallengeRechallenge results as csv

    -
    exportDechallengeRechallengeToCsv(result, saveDirectory)
    +
    exportDechallengeRechallengeToCsv(result, saveDirectory, minCellCount = 0)
    @@ -90,6 +90,10 @@

    Arguments

    saveDirectory

    An directory location to save the results into

    + +
    minCellCount
    +

    The minimum value that will be displayed in count columns

    +

    Value

    diff --git a/docs/reference/exportRechallengeFailCaseSeriesToCsv.html b/docs/reference/exportRechallengeFailCaseSeriesToCsv.html index ea6cd1c..1409775 100644 --- a/docs/reference/exportRechallengeFailCaseSeriesToCsv.html +++ b/docs/reference/exportRechallengeFailCaseSeriesToCsv.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5
    diff --git a/docs/reference/exportTimeToEventToCsv.html b/docs/reference/exportTimeToEventToCsv.html index fcd50ba..258e9e6 100644 --- a/docs/reference/exportTimeToEventToCsv.html +++ b/docs/reference/exportTimeToEventToCsv.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 @@ -78,7 +78,7 @@

    export the TimeToEvent results as csv

    -
    exportTimeToEventToCsv(result, saveDirectory)
    +
    exportTimeToEventToCsv(result, saveDirectory, minCellCount = 0)
    @@ -90,6 +90,10 @@

    Arguments

    saveDirectory

    An directory location to save the results into

    + +
    minCellCount
    +

    The minimum value that will be displayed in count columns

    +

    Value

    diff --git a/docs/reference/index.html b/docs/reference/index.html index 9c974ba..86949d3 100644 --- a/docs/reference/index.html +++ b/docs/reference/index.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5
    diff --git a/docs/reference/loadAggregateCovariateAnalyses.html b/docs/reference/loadAggregateCovariateAnalyses.html index 2bd1d85..60a1e79 100644 --- a/docs/reference/loadAggregateCovariateAnalyses.html +++ b/docs/reference/loadAggregateCovariateAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/loadCharacterizationSettings.html b/docs/reference/loadCharacterizationSettings.html index 272c8bb..c2a649b 100644 --- a/docs/reference/loadCharacterizationSettings.html +++ b/docs/reference/loadCharacterizationSettings.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/loadDechallengeRechallengeAnalyses.html b/docs/reference/loadDechallengeRechallengeAnalyses.html index 404959a..90b9001 100644 --- a/docs/reference/loadDechallengeRechallengeAnalyses.html +++ b/docs/reference/loadDechallengeRechallengeAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/loadRechallengeFailCaseSeriesAnalyses.html b/docs/reference/loadRechallengeFailCaseSeriesAnalyses.html index cab7d7a..6eb84c6 100644 --- a/docs/reference/loadRechallengeFailCaseSeriesAnalyses.html +++ b/docs/reference/loadRechallengeFailCaseSeriesAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/loadTimeToEventAnalyses.html b/docs/reference/loadTimeToEventAnalyses.html index f6fbc2f..9524be7 100644 --- a/docs/reference/loadTimeToEventAnalyses.html +++ b/docs/reference/loadTimeToEventAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/runCharacterizationAnalyses.html b/docs/reference/runCharacterizationAnalyses.html index b5a253c..f2afb6e 100644 --- a/docs/reference/runCharacterizationAnalyses.html +++ b/docs/reference/runCharacterizationAnalyses.html @@ -18,7 +18,7 @@ Characterization - 0.1.1 + 0.1.5 @@ -92,7 +92,8 @@

    execute a large-scale characterization study

    saveDirectory, tablePrefix = "c_", databaseId = "1", - showSubjectId = F + showSubjectId = F, + minCellCount = 0 )
    @@ -145,12 +146,16 @@

    Arguments

    databaseId
    -

    The unqiue identifier for the cdm database

    +

    The unique identifier for the cdm database

    showSubjectId

    Whether to include subjectId of failed rechallenge case series or hide

    + +
    minCellCount
    +

    The minimum count value that is calculated

    +

    Value

    diff --git a/docs/reference/saveAggregateCovariateAnalyses.html b/docs/reference/saveAggregateCovariateAnalyses.html index 55099f9..32da3b4 100644 --- a/docs/reference/saveAggregateCovariateAnalyses.html +++ b/docs/reference/saveAggregateCovariateAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5
    diff --git a/docs/reference/saveCharacterizationSettings.html b/docs/reference/saveCharacterizationSettings.html index da41528..77f30d8 100644 --- a/docs/reference/saveCharacterizationSettings.html +++ b/docs/reference/saveCharacterizationSettings.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 @@ -95,7 +95,7 @@

    Arguments

    Value

    -

    Returns the location of the drectory containing the json settings

    +

    Returns the location of the directory containing the json settings

    Details

    diff --git a/docs/reference/saveDechallengeRechallengeAnalyses.html b/docs/reference/saveDechallengeRechallengeAnalyses.html index db2a78a..b141793 100644 --- a/docs/reference/saveDechallengeRechallengeAnalyses.html +++ b/docs/reference/saveDechallengeRechallengeAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5
    diff --git a/docs/reference/saveRechallengeFailCaseSeriesAnalyses.html b/docs/reference/saveRechallengeFailCaseSeriesAnalyses.html index 948b610..5c4a6c1 100644 --- a/docs/reference/saveRechallengeFailCaseSeriesAnalyses.html +++ b/docs/reference/saveRechallengeFailCaseSeriesAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/saveTimeToEventAnalyses.html b/docs/reference/saveTimeToEventAnalyses.html index 9d1c0c8..58c8e4b 100644 --- a/docs/reference/saveTimeToEventAnalyses.html +++ b/docs/reference/saveTimeToEventAnalyses.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/reference/viewCharacterization.html b/docs/reference/viewCharacterization.html index 65184e8..dafe528 100644 --- a/docs/reference/viewCharacterization.html +++ b/docs/reference/viewCharacterization.html @@ -17,7 +17,7 @@ Characterization - 0.1.1 + 0.1.5 diff --git a/docs/sitemap.xml b/docs/sitemap.xml index a679701..140421f 100644 --- a/docs/sitemap.xml +++ b/docs/sitemap.xml @@ -4,13 +4,13 @@ /404.html - /articles/InstallationGuide.html + /articles/index.html - /articles/UsingCharacterizationPackage.html + /articles/InstallationGuide.html - /articles/index.html + /articles/UsingCharacterizationPackage.html /authors.html diff --git a/extras/Characterization.pdf b/extras/Characterization.pdf index 66746a4..9051939 100644 Binary files a/extras/Characterization.pdf and b/extras/Characterization.pdf differ diff --git a/extras/PackageMaintenance.R b/extras/PackageMaintenance.R index d5fe8b8..2118769 100644 --- a/extras/PackageMaintenance.R +++ b/extras/PackageMaintenance.R @@ -1,4 +1,4 @@ -# Copyright 2022 Observational Health Data Sciences and Informatics +# Copyright 2024 Observational Health Data Sciences and Informatics # # This file is part of Characterization # diff --git a/inst/doc/InstallationGuide.pdf b/inst/doc/InstallationGuide.pdf new file mode 100644 index 0000000..1250cac Binary files /dev/null and b/inst/doc/InstallationGuide.pdf differ diff --git a/inst/doc/UsingCharacterizationPackage.pdf b/inst/doc/UsingCharacterizationPackage.pdf new file mode 100644 index 0000000..553d7f0 Binary files /dev/null and b/inst/doc/UsingCharacterizationPackage.pdf differ diff --git a/inst/settings/resultsDataModelSpecification.csv b/inst/settings/resultsDataModelSpecification.csv index 29beb0a..4578e80 100644 --- a/inst/settings/resultsDataModelSpecification.csv +++ b/inst/settings/resultsDataModelSpecification.csv @@ -68,7 +68,7 @@ covariates,average_value,float,Y,N,N,N,The average value covariates_continuous,database_id,varchar(100),Y,Y,N,N,The database identifier covariates_continuous,run_id,int,Y,Y,N,N,The run identifier covariates_continuous,cohort_definition_id,bigint,Y,Y,N,N,The cohort definition id -covariates_continuous,covariate_id,int,Y,Y,N,N,The covariate identifier +covariates_continuous,covariate_id,bigint,Y,Y,N,N,The covariate identifier covariates_continuous,count_value,int,Y,N,N,N,The count value covariates_continuous,min_value,float,Y,N,N,N,The min value covariates_continuous,max_value,float,Y,N,N,N,The max value diff --git a/man/exportDatabaseToCsv.Rd b/man/exportDatabaseToCsv.Rd index e39f860..df9de08 100644 --- a/man/exportDatabaseToCsv.Rd +++ b/man/exportDatabaseToCsv.Rd @@ -10,7 +10,7 @@ exportDatabaseToCsv( targetDialect = NULL, tablePrefix = "c_", filePrefix = NULL, - tempEmulationSchema = NULL, + tempEmulationSchema = getOption("sqlRenderTempEmulationSchema"), saveDirectory, minMeanCovariateValue = 0.001 ) diff --git a/man/runCharacterizationAnalyses.Rd b/man/runCharacterizationAnalyses.Rd index 8ef7b71..501a38e 100644 --- a/man/runCharacterizationAnalyses.Rd +++ b/man/runCharacterizationAnalyses.Rd @@ -47,7 +47,7 @@ can be created} \item{tablePrefix}{A string to append the tables in the results} -\item{databaseId}{The unqiue identifier for the cdm database} +\item{databaseId}{The unique identifier for the cdm database} \item{showSubjectId}{Whether to include subjectId of failed rechallenge case series or hide} diff --git a/man/saveCharacterizationSettings.Rd b/man/saveCharacterizationSettings.Rd index 3c0e314..b08962a 100644 --- a/man/saveCharacterizationSettings.Rd +++ b/man/saveCharacterizationSettings.Rd @@ -12,7 +12,7 @@ saveCharacterizationSettings(settings, fileName) \item{fileName}{The location to save the json settings} } \value{ -Returns the location of the drectory containing the json settings +Returns the location of the directory containing the json settings } \description{ This function converts the settings into a json object and saves it diff --git a/tests/testthat/test-Database.R b/tests/testthat/test-Database.R index 20b3c6d..d223946 100644 --- a/tests/testthat/test-Database.R +++ b/tests/testthat/test-Database.R @@ -1,63 +1,62 @@ context("Database") test_that("removeMinCell", { -data <- data.frame(name = rep('dfd', 10), val = 1:10) -newData <- removeMinCell( - data = data, minCellCount = 5, minCellCountColumns = list() -) -testthat::expect_equal(newData, data) + data <- data.frame(name = rep("dfd", 10), val = 1:10) + newData <- removeMinCell( + data = data, minCellCount = 5, minCellCountColumns = list() + ) + testthat::expect_equal(newData, data) -newData <- removeMinCell( - data = data, minCellCount = 5, minCellCountColumns = list('val') -) -testthat::expect_equal(newData$val[5:10], data$val[5:10]) -testthat::expect_equal(newData$val[1:4], rep(-1,4)) + newData <- removeMinCell( + data = data, minCellCount = 5, minCellCountColumns = list("val") + ) + testthat::expect_equal(newData$val[5:10], data$val[5:10]) + testthat::expect_equal(newData$val[1:4], rep(-1, 4)) -newData <- removeMinCell( - data = data, minCellCount = 50, minCellCountColumns = list('val') -) -testthat::expect_equal(newData$val, rep(-1,10)) + newData <- removeMinCell( + data = data, minCellCount = 50, minCellCountColumns = list("val") + ) + testthat::expect_equal(newData$val, rep(-1, 10)) -data <- data.frame( - name = rep('dfd', 10), - val = 1:10, - val2 = c(1,10,1,10,1,10,1,10,1,10) -) -newData <- removeMinCell( - data = data, minCellCount = 5, minCellCountColumns = list('val') -) -testthat::expect_equal(newData$val[1:4], rep(-1,4)) -testthat::expect_equal(newData$val2, data$val2,) + data <- data.frame( + name = rep("dfd", 10), + val = 1:10, + val2 = c(1, 10, 1, 10, 1, 10, 1, 10, 1, 10) + ) + newData <- removeMinCell( + data = data, minCellCount = 5, minCellCountColumns = list("val") + ) + testthat::expect_equal(newData$val[1:4], rep(-1, 4)) + testthat::expect_equal(newData$val2, data$val2, ) -newData <- removeMinCell( - data = data, minCellCount = 5, minCellCountColumns = list(c('val','val2')) -) -testthat::expect_equal( - sum( - (newData$val > 0 & newData$val < 5) | (newData$val2 > 0 & newData$val2 < 5) - ), - 0 -) - -data <- data.frame( - name = rep('dfd', 10), - val = 1:10, - val2 = c(1,10,1,10,1,10,1,10,1,10), - val3 = c(10,10,10,10,10,1,1,10,10,10) -) -newData <- removeMinCell( - data = data, - minCellCount = 5, - minCellCountColumns = - list(c('val','val2'), 'val3') -) -testthat::expect_equal( - sum( - (newData$val > 0 & newData$val < 5) | - (newData$val2 > 0 & newData$val2 < 5) | - (newData$val3 > 0 & newData$val3 < 5) - ), - 0 -) + newData <- removeMinCell( + data = data, minCellCount = 5, minCellCountColumns = list(c("val", "val2")) + ) + testthat::expect_equal( + sum( + (newData$val > 0 & newData$val < 5) | (newData$val2 > 0 & newData$val2 < 5) + ), + 0 + ) + data <- data.frame( + name = rep("dfd", 10), + val = 1:10, + val2 = c(1, 10, 1, 10, 1, 10, 1, 10, 1, 10), + val3 = c(10, 10, 10, 10, 10, 1, 1, 10, 10, 10) + ) + newData <- removeMinCell( + data = data, + minCellCount = 5, + minCellCountColumns = + list(c("val", "val2"), "val3") + ) + testthat::expect_equal( + sum( + (newData$val > 0 & newData$val < 5) | + (newData$val2 > 0 & newData$val2 < 5) | + (newData$val3 > 0 & newData$val3 < 5) + ), + 0 + ) }) diff --git a/tests/testthat/test-aggregateCovariate.R b/tests/testthat/test-aggregateCovariate.R index 9f1e9d0..ca261ea 100644 --- a/tests/testthat/test-aggregateCovariate.R +++ b/tests/testthat/test-aggregateCovariate.R @@ -97,7 +97,7 @@ test_that("computeAggregateCovariateAnalyses", { testthat::expect_true(inherits(agc, "CovariateData")) testthat::expect_true(length(unique(as.data.frame(agc$covariates)$cohortDefinitionId)) - <= length(res$targetIds) * length(res$outcomeIds) * 4 + length(res$targetIds)*2 + length(res$outcomeIds)*2) + <= length(res$targetIds) * length(res$outcomeIds) * 4 + length(res$targetIds) * 2 + length(res$outcomeIds) * 2) testthat::expect_true( sum(names(agc) %in% c( "analysisRef", @@ -111,7 +111,7 @@ test_that("computeAggregateCovariateAnalyses", { testthat::expect_true( nrow(as.data.frame(agc$cohortDetails)) == - nrow(as.data.frame(agc$cohortCounts)) + nrow(as.data.frame(agc$cohortCounts)) ) # check cohortDetails diff --git a/tests/testthat/test-runCharacterization.R b/tests/testthat/test-runCharacterization.R index 5f3dbc9..9c86693 100644 --- a/tests/testthat/test-runCharacterization.R +++ b/tests/testthat/test-runCharacterization.R @@ -172,5 +172,4 @@ test_that("runCharacterizationAnalyses", { testthat::expect_true( file.exists(file.path(tempFolder, "csv", "time_to_event.csv")) ) - }) diff --git a/tests/testthat/test-timeToEvent.R b/tests/testthat/test-timeToEvent.R index b65d52c..20e1c76 100644 --- a/tests/testthat/test-timeToEvent.R +++ b/tests/testthat/test-timeToEvent.R @@ -99,7 +99,7 @@ test_that("computeTimeToEventSettings", { tte2 <- loadTimeToEventAnalyses(tempFile) - testthat::expect_equal(dplyr::collect(tte$timeToEvent ), dplyr::collect(tte2$timeToEvent)) + testthat::expect_equal(dplyr::collect(tte$timeToEvent), dplyr::collect(tte2$timeToEvent)) # test csv export tempFolder <- tempfile("exportToCsv") @@ -110,7 +110,7 @@ test_that("computeTimeToEventSettings", { saveDirectory = tempFolder ) - testthat::expect_true(file.exists(file.path(tempFolder,"time_to_event.csv"))) + testthat::expect_true(file.exists(file.path(tempFolder, "time_to_event.csv"))) # check it saved correctly and uses snake case res <- readr::read_csv( diff --git a/tests/testthat/test-viewShiny.R b/tests/testthat/test-viewShiny.R index 93599ad..60948d0 100644 --- a/tests/testthat/test-viewShiny.R +++ b/tests/testthat/test-viewShiny.R @@ -1,22 +1,21 @@ context("ViewShiny") # create a folder with results for the shiny app -resultLocation <- file.path(tempdir(), 'shinyResults') -if(!dir.exists(resultLocation)){ +resultLocation <- file.path(tempdir(), "shinyResults") +if (!dir.exists(resultLocation)) { dir.create(resultLocation, recursive = T) } test_that("is_installed", { - testthat::expect_equal(is_installed('FeatureExtraction'), T) - testthat::expect_equal(is_installed('MadeUp4u834t3f'), F) + testthat::expect_equal(is_installed("FeatureExtraction"), T) + testthat::expect_equal(is_installed("MadeUp4u834t3f"), F) }) test_that("ensure_installed", { - testthat::expect_equal(ensure_installed('FeatureExtraction'), NULL) + testthat::expect_equal(ensure_installed("FeatureExtraction"), NULL) }) test_that("prepareCharacterizationShiny works", { - targetIds <- c(1, 2, 4) outcomeIds <- c(3) @@ -89,41 +88,39 @@ test_that("prepareCharacterizationShiny works", { databaseId = "1" ) -settings <- prepareCharacterizationShiny( + settings <- prepareCharacterizationShiny( resultLocation = resultLocation, cohortDefinitionSet = NULL -) - -testthat::expect_true(settings$schema == 'main') -testthat::expect_true(settings$tablePrefix == 'c_') -testthat::expect_true(settings$cohortTablePrefix == 'cg_') -testthat::expect_true(settings$incidenceTablePrefix == 'i_') -testthat::expect_true(settings$databaseTable == 'DATABASE_META_DATA') - -connectionDetailsTest <- do.call( - what = DatabaseConnector::createConnectionDetails, - args = list( - dbms = 'sqlite', - server = file.path(resultLocation, 'sqliteCharacterization', 'sqlite.sqlite') ) -) -conTest <- DatabaseConnector::connect(connectionDetailsTest) -tables <- tolower( - DatabaseConnector::getTableNames( - connection = conTest, - databaseSchema = 'main' - ) -) -# make sure the extra tables are added -testthat::expect_true('cg_cohort_definition' %in% tables) -testthat::expect_true('database_meta_data' %in% tables) -testthat::expect_true('i_incidence_summary' %in% tables) + testthat::expect_true(settings$schema == "main") + testthat::expect_true(settings$tablePrefix == "c_") + testthat::expect_true(settings$cohortTablePrefix == "cg_") + testthat::expect_true(settings$incidenceTablePrefix == "i_") + testthat::expect_true(settings$databaseTable == "DATABASE_META_DATA") + + connectionDetailsTest <- do.call( + what = DatabaseConnector::createConnectionDetails, + args = list( + dbms = "sqlite", + server = file.path(resultLocation, "sqliteCharacterization", "sqlite.sqlite") + ) + ) + conTest <- DatabaseConnector::connect(connectionDetailsTest) + tables <- tolower( + DatabaseConnector::getTableNames( + connection = conTest, + databaseSchema = "main" + ) + ) + # make sure the extra tables are added + testthat::expect_true("cg_cohort_definition" %in% tables) + testthat::expect_true("database_meta_data" %in% tables) + testthat::expect_true("i_incidence_summary" %in% tables) }) test_that("shiny app works", { - settings <- prepareCharacterizationShiny( resultLocation = resultLocation, cohortDefinitionSet = NULL @@ -134,16 +131,13 @@ test_that("shiny app works", { testApp = T ) -shiny::testServer( - app = app, - args = list( - ), - expr = { - - testthat::expect_equal(runServer[['About']],0) - session$setInputs(menu = 'About') - testthat::expect_equal(runServer[['About']],1) - - }) - + shiny::testServer( + app = app, + args = list(), + expr = { + testthat::expect_equal(runServer[["About"]], 0) + session$setInputs(menu = "About") + testthat::expect_equal(runServer[["About"]], 1) + } + ) }) diff --git a/vignettes/InstallationGuide.Rmd b/vignettes/InstallationGuide.Rmd index 9552cfe..dd1bd41 100644 --- a/vignettes/InstallationGuide.Rmd +++ b/vignettes/InstallationGuide.Rmd @@ -29,7 +29,7 @@ output: --> # Introduction -This vignette describes how you need to install the Observational Health Data Sciencs and Informatics (OHDSI) [`Characterization`](http://github.com/OHDSI/Characterization) package under Windows, Mac, and Linux. +This vignette describes how you need to install the Observational Health Data Sciences and Informatics (OHDSI) [`Characterization`](http://github.com/OHDSI/Characterization) package under Windows, Mac, and Linux. # Software Prerequisites @@ -53,7 +53,7 @@ Under Mac and Linux the OHDSI Characterization package requires installing: # Installing the Package The preferred way to install the package is by using `remotes`, which will automatically install the latest release and all the latest dependencies. -If you do not want the official release you could install the bleading edge version of the package (latest develop branch). +If you do not want the official release you could install the bleeding edge version of the package (latest develop branch). Note that the latest develop branch could contain bugs, please report them to us if you experience problems. @@ -73,7 +73,7 @@ http://github.com/OHDSI/Characterization/issues The list below provides solutions for some common issues: -1. If you have an error when trying to install a package in R saying **'Dependancy X not available ...'** then this can sometimes be fixed by running `install.packages('X')` and then once that completes trying to reinstall the package that had the error. +1. If you have an error when trying to install a package in R saying **'Dependency X not available ...'** then this can sometimes be fixed by running `install.packages('X')` and then once that completes trying to reinstall the package that had the error. 2. I have found that using the github `remotes`` to install packages can be impacted if you have **multiple R sessions** open as one session with a library open can cause the library to be locked and this can prevent an install of a package that depends on that library. diff --git a/vignettes/UsingCharacterizationPackage.Rmd b/vignettes/UsingCharacterizationPackage.Rmd index d2ebdb3..db15f7e 100644 --- a/vignettes/UsingCharacterizationPackage.Rmd +++ b/vignettes/UsingCharacterizationPackage.Rmd @@ -31,8 +31,8 @@ output: # Introduction This vignette describes how you can use the Characterization package for various descriptive studies using OMOP CDM data. The Characterization package currently contains three different types of analyses: -- Aggreagate Covariates: this returns the mean feature value for a set of features specified by the user for i) the Target cohort population, ii) the Outcome cohort population, iii) the Target population patients who had the outcome during some user specified time-at-risk and iv) the Target population patients who did not have the outcome during some user specified time-at-risk. -- DechallengeRechallenge: this is mainly aimed at investigating whether a drug and event are causally related by seeing whether the drug is stopped close in time to the event occurrence (dechallenge) and then whether the drug is restarted (a rechallenge occurs) and if so, whether the event starts again (a failed rechallenge). In this analysis, the Target cohorts are the drug users of interest and the Outcome cohorts are the medical events you wish to see whether the drug may cause. The user must also specify how close in time a drug msut be stopped after the outcome to be considered a dechallenge and how close in time an Outcome must occur after restarting the drug to be considered a failed rechallenge). +- Aggregate Covariates: this returns the mean feature value for a set of features specified by the user for i) the Target cohort population, ii) the Outcome cohort population, iii) the Target population patients who had the outcome during some user specified time-at-risk and iv) the Target population patients who did not have the outcome during some user specified time-at-risk. +- DechallengeRechallenge: this is mainly aimed at investigating whether a drug and event are causally related by seeing whether the drug is stopped close in time to the event occurrence (dechallenge) and then whether the drug is restarted (a rechallenge occurs) and if so, whether the event starts again (a failed rechallenge). In this analysis, the Target cohorts are the drug users of interest and the Outcome cohorts are the medical events you wish to see whether the drug may cause. The user must also specify how close in time a drug must be stopped after the outcome to be considered a dechallenge and how close in time an Outcome must occur after restarting the drug to be considered a failed rechallenge). - Time-to-event: this returns descriptive results showing the timing between the target cohort and outcome. This can help identify whether the outcome often precedes the target cohort or whether it generally comes after. # Setup @@ -40,8 +40,8 @@ This vignette describes how you can use the Characterization package for various In this vignette we will show working examples using the `Eunomia` R package that contains simulated data. Run the following code to install the `Eunomia` R package: ```{r tidy=TRUE,eval=FALSE} -install.packages('remotes') -remotes::install_github('ohdsi/Eunomia') +install.packages("remotes") +remotes::install_github("ohdsi/Eunomia") ``` Eunomia can be used to create a temporary SQLITE database with the simulated data. The function `getEunomiaConnectionDetails` creates a SQLITE connection to a temporary location. The function `createCohorts` then populates the temporary SQLITE database with the simulated data ready to be used. @@ -53,8 +53,8 @@ Eunomia::createCohorts(connectionDetails = connectionDetails) We also need to have the Characterization package installed and loaded ```{r tidy=TRUE,eval=FALSE} -remotes::install_github('ohdsi/FeatureExtraction') -remotes::install_github('ohdsi/Characterization') +remotes::install_github("ohdsi/FeatureExtraction") +remotes::install_github("ohdsi/Characterization") ``` ```{r tidy=TRUE,eval=TRUE} @@ -79,45 +79,45 @@ To run an 'Aggregate Covariate' analysis you need to create a setting object usi Using the Eunomia data were we previous generated four cohorts, we can use cohort ids 1,2 and 4 as the targetIds and cohort id 3 as the outcomeIds: ```{r eval=TRUE} - exampleTargetIds <- c(1,2,4) - exampleOutcomeIds <- 3 +exampleTargetIds <- c(1, 2, 4) +exampleOutcomeIds <- 3 ``` If we want to get information on the sex assigned at birth, age at index and Charlson Comorbidity index we can create the settings using `FeatureExtraction::createCovariateSettings`: ```{r eval=TRUE} - exampleCovariateSettings <- FeatureExtraction::createCovariateSettings( - useDemographicsGender = T, - useDemographicsAge = T, - useCharlsonIndex = T - ) +exampleCovariateSettings <- FeatureExtraction::createCovariateSettings( + useDemographicsGender = T, + useDemographicsAge = T, + useCharlsonIndex = T +) ``` If we want to create the aggregate features for all our target cohorts, our outcome cohort and each target cohort restricted to those with a record of the outcome 1 day after target cohort start date until 365 days after target cohort end date we can run: ```{r eval=TRUE} - exampleAggregateCovariateSettings <- createAggregateCovariateSettings( - targetIds = exampleTargetIds, - outcomeIds = exampleOutcomeIds, - riskWindowStart = 1, startAnchor = 'cohort start', - riskWindowEnd = 365, endAnchor = 'cohort start', - covariateSettings = exampleCovariateSettings - ) +exampleAggregateCovariateSettings <- createAggregateCovariateSettings( + targetIds = exampleTargetIds, + outcomeIds = exampleOutcomeIds, + riskWindowStart = 1, startAnchor = "cohort start", + riskWindowEnd = 365, endAnchor = "cohort start", + covariateSettings = exampleCovariateSettings +) ``` -Next we need to use the `exampleAggregateCovariateSettings` as the settings to `computeAggregateCovariateAnalyses`, we need to use the Eunomia connectionDetails and in Eunomia the OMOP CDM data and cohort table are in the 'main' schema. The cohort table name is 'cohort'. The following code will apply the aggregative covariates analysis using the previously specified settings on the simulated Eunomia data: +Next we need to use the `exampleAggregateCovariateSettings` as the settings to `computeAggregateCovariateAnalyses`, we need to use the Eunomia connectionDetails and in Eunomia the OMOP CDM data and cohort table are in the 'main' schema. The cohort table name is 'cohort'. The following code will apply the aggregated covariates analysis using the previously specified settings on the simulated Eunomia data: ```{r eval=TRUE,results='hide',error=FALSE,warning=FALSE,message=FALSE} agc <- computeAggregateCovariateAnalyses( - connectionDetails = connectionDetails, - cdmDatabaseSchema = 'main', - cdmVersion = 5, - targetDatabaseSchema = 'main', - targetTable = 'cohort', - aggregateCovariateSettings = exampleAggregateCovariateSettings, - databaseId = 'Eunomia', - runId = 1 - ) + connectionDetails = connectionDetails, + cdmDatabaseSchema = "main", + cdmVersion = 5, + targetDatabaseSchema = "main", + targetTable = "cohort", + aggregateCovariateSettings = exampleAggregateCovariateSettings, + databaseId = "Eunomia", + runId = 1 +) ``` If you would like to save the results you can use the function `saveAggregateCovariateAnalyses` and this can then be loaded using `loadAggregateCovariateAnalyses`. @@ -126,30 +126,30 @@ The results are Andromeda objects that can we viewed using `dplyr`. There are f - covariates: ```{r eval=TRUE} -agc$covariates %>% +agc$covariates %>% collect() %>% - kableExtra::kbl() + kableExtra::kbl() ``` - covariatesContinuous: ```{r eval=TRUE} -agc$covariatesContinuous %>% +agc$covariatesContinuous %>% collect() %>% - kableExtra::kbl() + kableExtra::kbl() ``` - covariateRef: ```{r eval=TRUE} -agc$covariateRef %>% +agc$covariateRef %>% collect() %>% - kableExtra::kbl() + kableExtra::kbl() ``` - analysisRef: ```{r eval=TRUE} -agc$analysisRef %>% +agc$analysisRef %>% collect() %>% - kableExtra::kbl() + kableExtra::kbl() ``` ## Dechallenge Rechallenge @@ -164,31 +164,31 @@ To run a 'Dechallenge Rechallenge' analysis you need to create a setting object Using the Eunomia data were we previous generated four cohorts, we can use cohort ids 1,2 and 4 as the targetIds and cohort id 3 as the outcomeIds: ```{r eval=TRUE} - exampleTargetIds <- c(1,2,4) - exampleOutcomeIds <- 3 +exampleTargetIds <- c(1, 2, 4) +exampleOutcomeIds <- 3 ``` If we want to create the dechallenge rechallenge for all our target cohorts and our outcome cohort with a 30 day dechallengeStopInterval and 31 day dechallengeEvaluationWindow: ```{r eval=TRUE} - exampleDechallengeRechallengeSettings <- createDechallengeRechallengeSettings( - targetIds = exampleTargetIds, - outcomeIds = exampleOutcomeIds, - dechallengeStopInterval = 30, - dechallengeEvaluationWindow = 31 - ) +exampleDechallengeRechallengeSettings <- createDechallengeRechallengeSettings( + targetIds = exampleTargetIds, + outcomeIds = exampleOutcomeIds, + dechallengeStopInterval = 30, + dechallengeEvaluationWindow = 31 +) ``` We can then run the analysis on the Eunomia data using `computeDechallengeRechallengeAnalyses` and the settings previously specified: ```{r eval=TRUE} dc <- computeDechallengeRechallengeAnalyses( - connectionDetails = connectionDetails, - targetDatabaseSchema = 'main', - targetTable = 'cohort', - dechallengeRechallengeSettings = exampleDechallengeRechallengeSettings, - databaseId = 'Eunomia' - ) + connectionDetails = connectionDetails, + targetDatabaseSchema = "main", + targetTable = "cohort", + dechallengeRechallengeSettings = exampleDechallengeRechallengeSettings, + databaseId = "Eunomia" +) ``` If you would like to save the results you can use the function `saveDechallengeRechallengeAnalyses` and this can then be loaded using `loadDechallengeRechallengeAnalyses`. @@ -196,9 +196,9 @@ If you would like to save the results you can use the function `saveDechallengeR The results are Andromeda objects that can we viewed using `dplyr`. There is just one table named dechallengeRechallenge: ```{r eval=TRUE} -dc$dechallengeRechallenge %>% +dc$dechallengeRechallenge %>% collect() %>% - kableExtra::kbl() + kableExtra::kbl() ``` Next it is possible to computer and extract the failed rechallenge cases @@ -206,21 +206,21 @@ Next it is possible to computer and extract the failed rechallenge cases ```{r eval=TRUE} failed <- computeRechallengeFailCaseSeriesAnalyses( connectionDetails = connectionDetails, - targetDatabaseSchema = 'main', - targetTable = 'cohort', + targetDatabaseSchema = "main", + targetTable = "cohort", dechallengeRechallengeSettings = exampleDechallengeRechallengeSettings, - outcomeDatabaseSchema = 'main', - outcomeTable = 'cohort', - databaseId = 'Eunomia' + outcomeDatabaseSchema = "main", + outcomeTable = "cohort", + databaseId = "Eunomia" ) ``` The results are Andromeda objects that can we viewed using `dplyr`. There is just one table named rechallengeFailCaseSeries: ```{r eval=TRUE} -failed$rechallengeFailCaseSeries %>% +failed$rechallengeFailCaseSeries %>% collect() %>% - kableExtra::kbl() + kableExtra::kbl() ``` ## Time to Event @@ -231,23 +231,23 @@ To run a 'Time-to-event' analysis you need to create a setting object using `cre - one or more outcomeIds (these must be pre-generated in a cohort table) ```{r eval=TRUE} - exampleTimeToEventSettings <- createTimeToEventSettings( - targetIds = exampleTargetIds, - outcomeIds = exampleOutcomeIds - ) +exampleTimeToEventSettings <- createTimeToEventSettings( + targetIds = exampleTargetIds, + outcomeIds = exampleOutcomeIds +) ``` We can then run the analysis on the Eunomia data using `computeTimeToEventAnalyses` and the settings previously specified: ```{r eval=TRUE} tte <- computeTimeToEventAnalyses( - connectionDetails = connectionDetails, - cdmDatabaseSchema = 'main', - targetDatabaseSchema = 'main', - targetTable = 'cohort', - timeToEventSettings = exampleTimeToEventSettings, - databaseId = 'Eunomia' - ) + connectionDetails = connectionDetails, + cdmDatabaseSchema = "main", + targetDatabaseSchema = "main", + targetTable = "cohort", + timeToEventSettings = exampleTimeToEventSettings, + databaseId = "Eunomia" +) ``` If you would like to save the results you can use the function `saveTimeToEventAnalyses` and this can then be loaded using `loadTimeToEventAnalyses`. @@ -255,10 +255,10 @@ If you would like to save the results you can use the function `saveTimeToEventA The results are Andromeda objects that can we viewed using `dplyr`. There is just one table named timeToEvent: ```{r eval=TRUE} -tte$timeToEvent %>% +tte$timeToEvent %>% collect() %>% top_n(10) %>% - kableExtra::kbl() + kableExtra::kbl() ``` @@ -267,57 +267,56 @@ tte$timeToEvent %>% If you want to run multiple analyses (of the three previously shown) you can use `createCharacterizationSettings`. You need to input a list of each of the settings (or NULL if you do not want to run one type of analysis). To run all the analyses previously shown in one function: ```{r eval=FALSE,results='hide',error=FALSE,warning=FALSE,message=FALSE} - characterizationSettings <- createCharacterizationSettings( - timeToEventSettings = list( - exampleTimeToEventSettings - ), - dechallengeRechallengeSettings = list( - exampleDechallengeRechallengeSettings - ), - aggregateCovariateSettings = list( - exampleAggregateCovariateSettings - ) +characterizationSettings <- createCharacterizationSettings( + timeToEventSettings = list( + exampleTimeToEventSettings + ), + dechallengeRechallengeSettings = list( + exampleDechallengeRechallengeSettings + ), + aggregateCovariateSettings = list( + exampleAggregateCovariateSettings ) +) # save the settings using saveCharacterizationSettings( - settings = characterizationSettings, - saveDirectory = file.path(tempdir(), 'saveSettings') - ) + settings = characterizationSettings, + saveDirectory = file.path(tempdir(), "saveSettings") +) # the settings can be loaded characterizationSettings <- loadCharacterizationSettings( - saveDirectory = file.path(tempdir(), 'saveSettings') - ) + saveDirectory = file.path(tempdir(), "saveSettings") +) runCharacterizationAnalyses( connectionDetails = connectionDetails, - cdmDatabaseSchema = 'main', - targetDatabaseSchema = 'main', - targetTable = 'cohort', - outcomeDatabaseSchema = 'main', - outcomeTable = 'cohort', + cdmDatabaseSchema = "main", + targetDatabaseSchema = "main", + targetTable = "cohort", + outcomeDatabaseSchema = "main", + outcomeTable = "cohort", characterizationSettings = characterizationSettings, - saveDirectory = file.path(tempdir(), 'example'), - tablePrefix = 'c_', - databaseId = '1' + saveDirectory = file.path(tempdir(), "example"), + tablePrefix = "c_", + databaseId = "1" ) - ``` This will create an SQLITE database with all the analyses saved into the saveDirectory. You can export the results as csv files using: ```{r eval=FALSE} connectionDetailsT <- DatabaseConnector::createConnectionDetails( - dbms = 'sqlite', - server = file.path(tempdir(),'example','sqliteCharacterization', 'sqlite.sqlite') + dbms = "sqlite", + server = file.path(tempdir(), "example", "sqliteCharacterization", "sqlite.sqlite") ) exportDatabaseToCsv( connectionDetails = connectionDetailsT, - resultSchema = 'main', - targetDialect = 'sqlite', - tablePrefix = 'c_', - saveDirectory = file.path(tempdir(),'csv') + resultSchema = "main", + targetDialect = "sqlite", + tablePrefix = "c_", + saveDirectory = file.path(tempdir(), "csv") ) ```