Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
7e14387
attempt to patch count(*) overflow
msuchard Nov 5, 2024
5c30f74
Add migration instead of changing ResultTables.sql directly
anthonysena Nov 5, 2024
0bf7b01
Cast datediff as bigint to prevent arithmetic overflow (occurred on V…
ob325 Mar 15, 2025
ecad3b2
Merge pull request #74 from vinci-ohdsi/develop
jreps Mar 18, 2025
3bd82d4
Update CustomCovariates.R
jreps May 7, 2025
0416809
Update DESCRIPTION
jreps May 7, 2025
04b7762
updating vignettes
jreps May 7, 2025
bd093d2
Update R_CMD_check_Hades.yaml
jreps May 7, 2025
b953528
preparing for 2.1.4 release
jreps May 7, 2025
c8c3eae
minor bug and check warning fixes
jreps May 7, 2025
bd14fbd
putting examples in own directories
jreps May 7, 2025
8cff3c6
fixing example doc
jreps May 7, 2025
1e6dc25
changing examples
jreps May 8, 2025
3ef0b56
Update ViewShiny.R
jreps May 8, 2025
48885d4
update example doc and FE
jreps May 8, 2025
6d44cee
Update DESCRIPTION
jreps May 8, 2025
07c543c
adding failed case series csv check
jreps May 8, 2025
cc70d65
changing version ready for release
jreps May 8, 2025
0a8f231
batch aggregate csv
jreps Jun 26, 2025
cde8383
more csv aggregation updates
jreps Jun 26, 2025
8c616f9
Fix inconsistent PK designation in RDMS
anthonysena Jun 30, 2025
3a90c7c
Restore PK for min_characterization_mean
anthonysena Jun 30, 2025
41f2879
Merge pull request #77 from OHDSI/rdms-cleanup
jreps Jun 30, 2025
b346753
progressBar and complete csv updates
jreps Aug 28, 2025
4919732
Merge branch 'develop' of https://github.com/OHDSI/Characterization i…
jreps Aug 28, 2025
c7285f7
Update R_CMD_check_Hades.yaml
jreps Aug 28, 2025
ea027b9
Merge branch 'develop' into va_patch
anthonysena Aug 28, 2025
4637945
Update to make person_count bigint
anthonysena Aug 28, 2025
a1b0ee3
Rename migration file
anthonysena Aug 28, 2025
78d11cb
do over
anthonysena Aug 28, 2025
740bab9
Update DESCRIPTION
jreps Aug 28, 2025
b017b9e
Update R_CMD_check_Hades.yaml
jreps Aug 28, 2025
695df04
Fix migration file order
anthonysena Aug 28, 2025
a52467e
Update R_CMD_check_Hades.yaml
jreps Aug 28, 2025
4550db5
Merge pull request #63 from OHDSI/va_patch
jreps Aug 28, 2025
c617246
Single quotes for constants in SQL and use rlang::inform to report er…
anthonysena Sep 2, 2025
58b6783
preparing for release
jreps Sep 2, 2025
5517db5
Update SQL syntax for SqlRender translation; properly emit error message
anthonysena Sep 2, 2025
614f426
One more SQL fix
anthonysena Sep 2, 2025
2132eaa
Merge pull request #80 from OHDSI/issue-79
jreps Sep 2, 2025
a4eeacb
Update ViewShiny.R
jreps Sep 9, 2025
f9e5c41
Merge branch 'develop' of https://github.com/OHDSI/Characterization i…
jreps Sep 9, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/R_CMD_check_Hades.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
config:
- {os: windows-latest, r: 'release'}
- {os: macOS-latest, r: 'release'}
- {os: ubuntu-20.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/focal/latest"}
- {os: ubuntu-22.04, r: 'release', rtools: ''}

env:
GITHUB_PAT: ${{ secrets.GH_TOKEN }}
Expand Down Expand Up @@ -77,12 +77,15 @@ jobs:
- name: Install system requirements
if: runner.os == 'Linux'
run: |
sudo apt-get install -y make
sudo apt-get install -y libcurl4-openssl-dev
sudo apt-get install -y libssh-dev
sudo apt-get install -y libssl-dev
Rscript -e 'install.packages("remotes")'
while read -r cmd
do
eval sudo $cmd
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "20.04"))')
done < <(Rscript -e 'writeLines(remotes::system_requirements("ubuntu", "22.04"))')

- uses: r-lib/actions/setup-r-dependencies@v2
with:
Expand Down
9 changes: 5 additions & 4 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
Package: Characterization
Type: Package
Title: Implement Descriptive Studies Using the Common Data Model
Version: 2.1.3
Date: 2025-2-26
Version: 2.2.0
Date: 2025-8-28
Authors@R: c(
person("Jenna", "Reps", , "jreps@its.jnj.com", role = c("aut", "cre")),
person("Patrick", "Ryan", , "ryan@ohdsi.org", role = c("aut")),
Expand All @@ -16,9 +16,9 @@ BugReports: https://github.com/OHDSI/Characterization/issues
Depends:
R (>= 4.0.0)
Imports:
Andromeda,
Andromeda (>= 1.0.0),
DatabaseConnector (>= 6.3.1),
FeatureExtraction (>= 3.6.0),
FeatureExtraction (>= 3.10.0),
SqlRender (>= 1.9.0),
ParallelLogger (>= 3.0.0),
ResultModelManager,
Expand All @@ -28,6 +28,7 @@ Imports:
rlang
Suggests:
devtools,
formatR,
testthat,
kableExtra,
knitr,
Expand Down
12 changes: 12 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
Characterization 2.2.0
======================
- fixed csv spec: made mean_exposure_time a float and specified that min_characterization_mean in covariate table must be non-null and is in the pk.
- changed Line 284 in AggregateCovariates.R to cast exposure_time summary values to bigint due to integer overflow in some dbms.
- added dummy sql code to prevent warnings about missing variables
- added code to save empty csv files when there are no rows as that way it is easier to see there are no results vs an error saving.
- removed progress bar from custom during features
- added option includedFiles in insertResultsToDatabase() where you can specify the csv files to upload to prevent warnings of missing csv files.
- made sure all connections are disconnected after use
- fixed counts to use count_big (thanks Anthony Sena) to fix an issue where the number was bigger than an integer.
- added code to copy csv files in batches this is needed when the csv files are very large.

Characterization 2.1.3
======================
- prepared for CRAN by adding examples, removing getwd(), replacing T/F with TRUE/FALSE and added example data inside package so no download required.
Expand Down
32 changes: 18 additions & 14 deletions R/AggregateCovariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ computeTargetAggregateCovariateAnalyses <- function(
outputFolder,
minCharacterizationMean = 0,
minCellCount = 0,
progressBar = interactive(),
...) {

if(missing(outputFolder)){
Expand Down Expand Up @@ -251,7 +252,7 @@ computeTargetAggregateCovariateAnalyses <- function(
tempTable = TRUE,
dropTableIfExists = TRUE,
createTable = TRUE,
progressBar = FALSE,
progressBar = progressBar,
tempEmulationSchema = tempEmulationSchema
)

Expand All @@ -273,7 +274,7 @@ computeTargetAggregateCovariateAnalyses <- function(
DatabaseConnector::executeSql(
connection = connection,
sql = sql,
progressBar = FALSE,
progressBar = progressBar,
reportOverallTime = FALSE
)
completionTime <- Sys.time() - start
Expand All @@ -283,11 +284,11 @@ computeTargetAggregateCovariateAnalyses <- function(
message("Extracting target cohort counts")
sql <- "select
cohort_definition_id,
count(*) row_count,
count(distinct subject_id) person_count,
min(datediff(day, cohort_start_date, cohort_end_date)) min_exposure_time,
avg(datediff(day, cohort_start_date, cohort_end_date)) mean_exposure_time,
max(datediff(day, cohort_start_date, cohort_end_date)) max_exposure_time
count_big(*) row_count,
count_big(distinct subject_id) person_count,
min(cast(datediff(day, cohort_start_date, cohort_end_date) as bigint)) min_exposure_time,
avg(cast(datediff(day, cohort_start_date, cohort_end_date) as bigint)) mean_exposure_time,
max(cast(datediff(day, cohort_start_date, cohort_end_date) as bigint)) max_exposure_time
from
(select * from #agg_cohorts_before union select * from #agg_cohorts_extras) temp
group by cohort_definition_id;"
Expand All @@ -299,7 +300,7 @@ computeTargetAggregateCovariateAnalyses <- function(
counts <- DatabaseConnector::querySql(
connection = connection,
sql = sql,
snakeCaseToCamelCase = TRUE,
snakeCaseToCamelCase = TRUE
)

message("Target Aggregate: Computing aggregate target covariate results")
Expand Down Expand Up @@ -327,7 +328,8 @@ computeTargetAggregateCovariateAnalyses <- function(
)
DatabaseConnector::executeSql(
connection = connection,
sql = sql, progressBar = FALSE,
sql = sql,
progressBar = progressBar,
reportOverallTime = FALSE
)

Expand Down Expand Up @@ -363,6 +365,7 @@ computeCaseAggregateCovariateAnalyses <- function(
outputFolder,
minCharacterizationMean = 0,
minCellCount = 0,
progressBar = interactive(),
...) {

if(missing(outputFolder)){
Expand Down Expand Up @@ -443,7 +446,7 @@ computeCaseAggregateCovariateAnalyses <- function(
tempTable = TRUE,
dropTableIfExists = TRUE,
createTable = TRUE,
progressBar = FALSE,
progressBar = progressBar,
tempEmulationSchema = tempEmulationSchema
)

Expand All @@ -469,7 +472,7 @@ computeCaseAggregateCovariateAnalyses <- function(
DatabaseConnector::executeSql(
connection = connection,
sql = sql,
progressBar = FALSE,
progressBar = progressBar,
reportOverallTime = FALSE
)

Expand All @@ -495,7 +498,7 @@ computeCaseAggregateCovariateAnalyses <- function(
DatabaseConnector::executeSql(
connection = connection,
sql = sql,
progressBar = FALSE,
progressBar = progressBar,
reportOverallTime = FALSE
)
}
Expand All @@ -522,7 +525,7 @@ computeCaseAggregateCovariateAnalyses <- function(
counts <- DatabaseConnector::querySql(
connection = connection,
sql = sql,
snakeCaseToCamelCase = TRUE,
snakeCaseToCamelCase = TRUE
)

message("Case Aggregates: Computing aggregate before case covariate results")
Expand Down Expand Up @@ -576,7 +579,8 @@ computeCaseAggregateCovariateAnalyses <- function(
)
DatabaseConnector::executeSql(
connection = connection,
sql = sql, progressBar = FALSE,
sql = sql,
progressBar = progressBar,
reportOverallTime = FALSE
)

Expand Down
19 changes: 13 additions & 6 deletions R/CustomCovariates.R
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,8 @@ createDuringCovariateSettings <- function(
#' cohortTable = 'cohort'
#' )
#'
#' DatabaseConnector::disconnect(connection)
#'
#' @return
#' A 'FeatureExtraction' covariateData object containing the during covariates based on user settings
#'
Expand All @@ -171,6 +173,8 @@ getDbDuringCovariateData <- function(

getDomainSettings <- utils::read.csv(system.file("csv/PrespecAnalyses.csv", package = "Characterization"))

# not showing progress
progressBar <- FALSE

# create Tables
sql <- "DROP TABLE IF EXISTS #cov_ref;
Expand All @@ -187,7 +191,7 @@ getDbDuringCovariateData <- function(
targetDialect = DatabaseConnector::dbms(connection),
tempEmulationSchema = tempEmulationSchema
)
DatabaseConnector::executeSql(connection, sql = sql)
DatabaseConnector::executeSql(connection, sql = sql, progressBar = progressBar)

sql <- "DROP TABLE IF EXISTS #analysis_ref;
CREATE TABLE #analysis_ref(
Expand All @@ -204,7 +208,7 @@ getDbDuringCovariateData <- function(
targetDialect = DatabaseConnector::dbms(connection),
tempEmulationSchema = tempEmulationSchema
)
DatabaseConnector::executeSql(connection, sql)
DatabaseConnector::executeSql(connection, sql, progressBar = progressBar)

# included covariates
includedCovTable <- ""
Expand All @@ -219,7 +223,8 @@ getDbDuringCovariateData <- function(
tempTable = TRUE,
data = data.frame(id = covariateSettings$includedCovariateIds),
camelCaseToSnakeCase = TRUE,
tempEmulationSchema = tempEmulationSchema
tempEmulationSchema = tempEmulationSchema,
progressBar = progressBar
)
}

Expand All @@ -235,7 +240,8 @@ getDbDuringCovariateData <- function(
tempTable = TRUE,
data = data.frame(id = covariateSettings$includedCovariateConceptIds),
camelCaseToSnakeCase = TRUE,
tempEmulationSchema = tempEmulationSchema
tempEmulationSchema = tempEmulationSchema,
progressBar = progressBar
)

if (covariateSettings$addDescendantsToInclude) {
Expand All @@ -262,7 +268,8 @@ getDbDuringCovariateData <- function(
tempTable = TRUE,
data = data.frame(id = covariateSettings$excludedCovariateConceptIds),
camelCaseToSnakeCase = TRUE,
tempEmulationSchema = tempEmulationSchema
tempEmulationSchema = tempEmulationSchema,
progressBar = progressBar
)

if (covariateSettings$addDescendantsToInclude) {
Expand Down Expand Up @@ -325,7 +332,7 @@ getDbDuringCovariateData <- function(
DatabaseConnector::executeSql(
connection = connection,
sql = sql,
progressBar = TRUE
progressBar = progressBar
)
time <- Sys.time() - start
message(paste0("Execution took ", round(time, digits = 2), " ", units(time)))
Expand Down
38 changes: 26 additions & 12 deletions R/Database.R
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ createSqliteDatabase <- function(
#' @param resultsFolder The folder containing the csv results
#' @param tablePrefix A prefix to append to the result tables for the characterization results
#' @param csvTablePrefix The prefix added to the csv results - default is 'c_'
#' @param includedFiles Specify the csv files to upload or NULL to upload all in directory
#' @family Database
#' @return
#' Returns the connection to the sqlite database
Expand All @@ -79,13 +80,13 @@ createSqliteDatabase <- function(
#' # generate results into resultsFolder
#' conDet <- exampleOmopConnectionDetails()
#'
#' drSet <- createDechallengeRechallengeSettings(
#' targetIds = c(1,2),
#' tteSet <- createTimeToEventSettings(
#' targetIds = c(1,2),
#' outcomeIds = 3
#' )
#' )
#'
#' cSet <- createCharacterizationSettings(
#' dechallengeRechallengeSettings = drSet
#' timeToEventSettings = tteSet
#' )
#'
#' runCharacterizationAnalyses(
Expand All @@ -96,7 +97,7 @@ createSqliteDatabase <- function(
#' outcomeTable = 'cohort',
#' cdmDatabaseSchema = 'main',
#' characterizationSettings = cSet,
#' outputDirectory = tempdir()
#' outputDirectory = file.path(tempdir(),'database')
#' )
#'
#' # create sqlite database
Expand All @@ -112,7 +113,8 @@ createSqliteDatabase <- function(
#' insertResultsToDatabase(
#' connectionDetails = charResultDbCD,
#' schema = 'main',
#' resultsFolder = tempdir()
#' resultsFolder = file.path(tempdir(),'database'),
#' includedFiles = c('time_to_event')
#' )
#'
#'
Expand All @@ -122,11 +124,16 @@ insertResultsToDatabase <- function(
schema,
resultsFolder,
tablePrefix = "",
csvTablePrefix = "c_") {
csvTablePrefix = "c_",
includedFiles = NULL
) {
specLoc <- system.file("settings", "resultsDataModelSpecification.csv",
package = "Characterization"
)
specs <- utils::read.csv(specLoc)
if(!is.null(includedFiles)){
specs <- specs[specs$table_name %in% includedFiles,]
}
colnames(specs) <- SqlRender::snakeCaseToCamelCase(colnames(specs))
specs$tableName <- paste0(csvTablePrefix, specs$tableName)
ResultModelManager::uploadResults(
Expand Down Expand Up @@ -253,7 +260,8 @@ createCharacterizationTables <- function(
)
DatabaseConnector::executeSql(
connection = conn,
sql = sql
sql = sql,
progressBar = FALSE
)

sql <- "DROP TABLE @my_schema.@table"
Expand All @@ -269,7 +277,8 @@ createCharacterizationTables <- function(
)
DatabaseConnector::executeSql(
connection = conn,
sql = sql
sql = sql,
progressBar = FALSE
)
}
}
Expand All @@ -288,10 +297,11 @@ createCharacterizationTables <- function(

DatabaseConnector::executeSql(
connection = conn,
sql = renderedSql
sql = renderedSql,
progressBar = FALSE
)

# add database migration here in the future
## add database migration here in the future
migrateDataModel(
connectionDetails = connectionDetails,
connection = conn,
Expand Down Expand Up @@ -329,7 +339,11 @@ migrateDataModel <- function(
connection <- DatabaseConnector::connect(connectionDetails = connectionDetails)
on.exit(DatabaseConnector::disconnect(connection))
}
DatabaseConnector::executeSql(connection, updateVersionSql)
DatabaseConnector::executeSql(
connection = connection,
sql = updateVersionSql,
progressBar = FALSE
)
}


Expand Down
Loading
Loading