cdmSubset
will return a new cdm object that contains lazy queries pointing
to each of the cdm tables but subset to individuals in a generated cohort.
Since the cdm tables are lazy queries, the subset operation will only be
done when the tables are used. computeQuery
can be used to run the SQL
used to subset a cdm table and store it as a new table in the database.
Value
A modified cdm_reference with all clinical tables subset to just the persons in the selected cohorts.
Examples
if (FALSE) { # \dontrun{
library(CDMConnector)
library(dplyr, warn.conflicts = FALSE)
con <- DBI::dbConnect(duckdb::duckdb(), eunomiaDir())
cdm <- cdmFromCon(con, cdmSchema = "main", writeSchema = "main")
# generate a cohort
path <- system.file("cohorts2", mustWork = TRUE, package = "CDMConnector")
cohortSet <- readCohortSet(path) %>%
filter(cohort_name == "GIBleed_male")
# subset cdm to persons in the generated cohort
cdm <- generateCohortSet(cdm, cohortSet = cohortSet, name = "gibleed")
cdmGiBleed <- cdmSubsetCohort(cdm, cohortTable = "gibleed")
cdmGiBleed$person %>%
tally()
#> # Source: SQL [1 x 1]
#> # Database: DuckDB 0.6.1
#> n
#> <dbl>
#> 1 237
cdm$person %>%
tally()
#> # Source: SQL [1 x 1]
#> # Database: DuckDB 0.6.1
#> n
#> <dbl>
#> 1 2694
DBI::dbDisconnect(con, shutdown = TRUE)
} # }