export: export

View source: R/export.R

exportR Documentation

export

Description

Export andromeda generated by computePathways object to sharable csv-files and/or a zip archive.

Usage

export(
  andromeda,
  outputPath,
  ageWindow = 10,
  minCellCount = 5,
  censorType = "minCellCount",
  archiveName = NULL
)

Arguments

andromeda

(Andromeda::andromeda()) Andromeda object.

outputPath

(character(1))

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 group 0-18 which includes subjects ⁠< 19⁠. And age group 18-150 which includes subjects ⁠> 18⁠.

minCellCount

(integer(1): 5)
Minimum count required per pathway. Censors data below x as ⁠<x⁠. This minimum value will carry over to the sankey diagram and sunburst plot.

censorType

(character(1))

"minCellCount"

Censors pathways <minCellCount to minCellCount.

"remove"

Censors pathways <minCellCount by removing them completely.

"mean"

Censors pathways <minCellCount to the mean of all frequencies below minCellCount

archiveName

(character(1): NULL)
If not NULL adds the exported files to a ZIP-file with the specified archive name.

Value

(invisible(NULL))

Examples


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
  )

  export(
    andromeda = outputEnv,
    outputPath = tempdir()
  )

  Andromeda::close(outputEnv)
  DBI::dbDisconnect(con, shutdown = TRUE)
}


TreatmentPatterns documentation built on Sept. 11, 2024, 8:59 p.m.