Export andromeda generated by computePathways object to sharable csv-files and/or a zip archive.
Usage
export(
andromeda,
outputPath = NULL,
ageWindow = 10,
minCellCount = 5,
censorType = "minCellCount",
archiveName = NULL,
nonePaths = FALSE,
stratify = FALSE
)
Arguments
- andromeda
(
Andromeda::andromeda()
) Andromeda object.- outputPath
(
character
:NULL
) Output path where to write output files to. When set toNULL
no files will be written, and only the results object is returned.- ageWindow
(
integer(n)
:10
)
Number of years to bin age groups into. It may also be a vector of integers. I.e.c(0, 18, 150)
which will results in age group0-18
which includes subjects< 19
. And age group18-150
which includes subjects> 18
.- minCellCount
(
integer(1)
:5
)
Minimum count required per pathway. Censors data belowx
as<x
. This minimum value will carry over to the sankey diagram and sunburst plot.- censorType
(
character(1)
)"minCellCount"
Censors pathways <
minCellCount
tominCellCount
."remove"
Censors pathways <
minCellCount
by removing them completely."mean"
Censors pathways <
minCellCount
to the mean of all frequencies belowminCellCount
- archiveName
(
character(1)
:NULL
)
If notNULL
adds the exported files to a ZIP-file with the specified archive name.- nonePaths
(
logical(1)
) ShouldNone
paths be included? This will fetch all persons included in the target cohort and assign them a"None"
pathway. Significantly impacts performance.- stratify
(
logical(1)
) Should pathways be stratified? This will perform pairwise stratification between age, sex, and index year. Significantly impacts performance.
Examples
# \donttest{
ableToRun <- all(
require("CirceR", character.only = TRUE, quietly = TRUE),
require("CDMConnector", character.only = TRUE, quietly = TRUE),
require("TreatmentPatterns", character.only = TRUE, quietly = TRUE),
require("dplyr", character.only = TRUE, quietly = TRUE)
)
if (ableToRun) {
library(TreatmentPatterns)
library(CDMConnector)
library(dplyr)
withr::local_envvar(
R_USER_CACHE_DIR = tempfile(),
EUNOMIA_DATA_FOLDER = Sys.getenv("EUNOMIA_DATA_FOLDER", unset = tempfile())
)
tryCatch({
if (Sys.getenv("skip_eunomia_download_test") != "TRUE") {
CDMConnector::downloadEunomiaData(overwrite = TRUE)
}
}, error = function(e) NA)
con <- DBI::dbConnect(duckdb::duckdb(), dbdir = eunomia_dir())
cdm <- cdmFromCon(con, cdmSchema = "main", writeSchema = "main")
cohortSet <- readCohortSet(
path = system.file(package = "TreatmentPatterns", "exampleCohorts")
)
cdm <- generateCohortSet(
cdm = cdm,
cohortSet = cohortSet,
name = "cohort_table"
)
cohorts <- cohortSet %>%
# Remove 'cohort' and 'json' columns
select(-"cohort", -"json") %>%
mutate(type = c("event", "event", "event", "event", "exit", "event", "event", "target")) %>%
rename(
cohortId = "cohort_definition_id",
cohortName = "cohort_name",
) %>%
select("cohortId", "cohortName", "type")
outputEnv <- computePathways(
cohorts = cohorts,
cohortTableName = "cohort_table",
cdm = cdm
)
results <- export(
andromeda = outputEnv
)
Andromeda::close(outputEnv)
DBI::dbDisconnect(con, shutdown = TRUE)
}
#>
#> Download completed!
#> Creating CDM database /tmp/RtmpsdqEev/file25072c2c4a9b/GiBleed_5.3.zip
#> ! cdm name not specified and could not be inferred from the cdm source table
#> ℹ Generating 8 cohorts
#> ℹ Generating cohort (1/8) - acetaminophen
#> ✔ Generating cohort (1/8) - acetaminophen [159ms]
#>
#> ℹ Generating cohort (2/8) - amoxicillin
#> ✔ Generating cohort (2/8) - amoxicillin [146ms]
#>
#> ℹ Generating cohort (3/8) - aspirin
#> ✔ Generating cohort (3/8) - aspirin [154ms]
#>
#> ℹ Generating cohort (4/8) - clavulanate
#> ✔ Generating cohort (4/8) - clavulanate [146ms]
#>
#> ℹ Generating cohort (5/8) - death
#> ✔ Generating cohort (5/8) - death [122ms]
#>
#> ℹ Generating cohort (6/8) - doxylamine
#> ✔ Generating cohort (6/8) - doxylamine [137ms]
#>
#> ℹ Generating cohort (7/8) - penicillinv
#> ✔ Generating cohort (7/8) - penicillinv [144ms]
#>
#> ℹ Generating cohort (8/8) - viralsinusitis
#> ✔ Generating cohort (8/8) - viralsinusitis [206ms]
#>
#> -- Qualifying records for cohort definitions: 1, 2, 3, 4, 5, 6, 7, 8
#> Records: 14041
#> Subjects: 2693
#> -- Removing records < minEraDuration (0)
#> Records: 11386
#> Subjects: 2159
#> >> Starting on target: 8 (viralsinusitis)
#> -- Removing events where index date < target index date + indexDateOffset (0)
#> Records: 8381
#> Subjects: 2159
#> -- splitEventCohorts
#> Records: 8366
#> Subjects: 2144
#> -- Collapsing eras, eraCollapse (30)
#> Records: 8366
#> Subjects: 2144
#> -- Iteration 1: minPostCombinationDuration (30), combinatinoWindow (30)
#> Records: 558
#> Subjects: 512
#> -- Iteration 2: minPostCombinationDuration (30), combinatinoWindow (30)
#> Records: 554
#> Subjects: 512
#> -- After Combination
#> Records: 554
#> Subjects: 512
#> -- filterTreatments (First)
#> Records: 553
#> Subjects: 512
#> -- treatment construction done
#> Records: 553
#> Subjects: 512
# }