Skip to content

Allow multiple arguments for analytic parameters #272

@edward-burn

Description

@edward-burn

Is your feature request related to a problem? Please describe.
Often we want to run treatment patterns with different analytic settings to see the impact of our decisions.

Describe the solution you'd like
Allow multiple inputs to be passed to the relevant parameters

Describe alternatives you've considered
Do a loop, calling the function multiple time. This works, but then every time the same cohort table is being collected, etc, so is rather slow and inefficient.

Additional context
Would be nice if the below worked

library(CDMConnector)
#> Warning: package 'CDMConnector' was built under R version 4.4.2
library(TreatmentPatterns)
#> Warning: package 'TreatmentPatterns' was built under R version 4.4.2
library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

cohortSet <- readCohortSet(
  path = system.file(package = "TreatmentPatterns", "exampleCohorts")
)

con <- DBI::dbConnect(
  drv = duckdb::duckdb(),
  dbdir = eunomia_dir()
)
#> Warning: `eunomia_dir()` was deprecated in CDMConnector 1.7.0.
#> ℹ Please use `eunomiaDir()` instead.
#> This warning is displayed once every 8 hours.
#> Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
#> generated.

cdm <- cdmFromCon(
  con = con,
  cdmSchema = "main",
  writeSchema = "main"
)
#> Note: method with signature 'DBIConnection#Id' chosen for function 'dbExistsTable',
#>  target signature 'duckdb_connection#Id'.
#>  "duckdb_connection#ANY" would also be valid
#> ! cdm name not specified and could not be inferred from the cdm source table
cdm <- generateCohortSet(
  cdm = cdm,
  cohortSet = cohortSet,
  name = "cohort_table",
  overwrite = TRUE
)
#> ℹ Generating 8 cohorts
#> ℹ Generating cohort (1/8) - acetaminophen✔ Generating cohort (1/8) - acetaminophen [812ms]
#> ℹ Generating cohort (2/8) - amoxicillin✔ Generating cohort (2/8) - amoxicillin [537ms]
#> ℹ Generating cohort (3/8) - aspirin✔ Generating cohort (3/8) - aspirin [521ms]
#> ℹ Generating cohort (4/8) - clavulanate✔ Generating cohort (4/8) - clavulanate [409ms]
#> ℹ Generating cohort (5/8) - death✔ Generating cohort (5/8) - death [277ms]
#> ℹ Generating cohort (6/8) - doxylamine✔ Generating cohort (6/8) - doxylamine [396ms]
#> ℹ Generating cohort (7/8) - penicillinv✔ Generating cohort (7/8) - penicillinv [416ms]
#> ℹ Generating cohort (8/8) - viralsinusitis✔ Generating cohort (8/8) - viralsinusitis [567ms]

cohorts <- cohortSet %>%
  # Remove 'cohort' and 'json' columns
  select(-"cohort", -"json", -"cohort_name_snakecase") %>%
  mutate(type = c("event", "event", "event", "event", "exit", "event", "event", "target")) %>%
  rename(
    cohortId = "cohort_definition_id",
    cohortName = "cohort_name",
  )

computePathways(
  cohorts = cohorts,
  cohortTableName = "cohort_table",
  cdm = cdm, 
  minEraDuration = c(0, 30), 
  eraCollapseSize = c(0, 30), 
  combinationWindow =  c(0, 30), 
)
#> Error in if (args$minEraDuration > args$minPostCombinationDuration) {: the condition has length > 1

Created on 2025-01-17 with reprex v2.1.0

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions