diff --git a/R/sampleCohorts.R b/R/sampleCohorts.R index 65df8184..bef67459 100644 --- a/R/sampleCohorts.R +++ b/R/sampleCohorts.R @@ -5,7 +5,7 @@ #' people. All records of these individuals are preserved. #' #' @inheritParams cohortDoc -#' @inheritParams cohortIdSubsetDoc +#' @inheritParams cohortIdModifyDoc #' @inheritParams nameDoc #' @param n Number of people to be sampled for each included cohort. #' diff --git a/man/sampleCohorts.Rd b/man/sampleCohorts.Rd index 68dbd93c..128b6b0b 100644 --- a/man/sampleCohorts.Rd +++ b/man/sampleCohorts.Rd @@ -9,9 +9,10 @@ sampleCohorts(cohort, cohortId = NULL, n, name = tableName(cohort)) \arguments{ \item{cohort}{A cohort table in a cdm reference.} -\item{cohortId}{Vector identifying which cohorts to include -(cohort_definition_id or cohort_name). Cohorts not included will be -removed from the cohort set.} +\item{cohortId}{Vector identifying which cohorts to modify +(cohort_definition_id or cohort_name). If NULL, all cohorts will be +used; otherwise, only the specified cohorts will be modified, and the +rest will remain unchanged.} \item{n}{Number of people to be sampled for each included cohort.} diff --git a/vignettes/a07_filter_cohorts.Rmd b/vignettes/a07_filter_cohorts.Rmd index f2fc2d18..db30b2f0 100644 --- a/vignettes/a07_filter_cohorts.Rmd +++ b/vignettes/a07_filter_cohorts.Rmd @@ -1,8 +1,8 @@ --- -title: "a06_filter_cohorts" +title: "Filter Cohorts" output: rmarkdown::html_vignette vignette: > - %\VignetteIndexEntry{a06_filter_cohorts} + %\VignetteIndexEntry{a07_filter_cohorts} %\VignetteEngine{knitr::rmarkdown} %\VignetteEncoding{UTF-8} --- @@ -16,4 +16,47 @@ knitr::opts_chunk$set( ```{r setup} library(CohortConstructor) +library(CohortCharacteristics) +library(ggplot2) +``` + +```{r, include = FALSE} +knitr::opts_chunk$set( + collapse = TRUE, + eval = TRUE, message = FALSE, warning = FALSE, + comment = "#>" +) + +library(CDMConnector) +library(dplyr, warn.conflicts = FALSE) + +if (Sys.getenv("EUNOMIA_DATA_FOLDER") == ""){ + Sys.setenv("EUNOMIA_DATA_FOLDER" = file.path(tempdir(), "eunomia"))} +if (!dir.exists(Sys.getenv("EUNOMIA_DATA_FOLDER"))){ dir.create(Sys.getenv("EUNOMIA_DATA_FOLDER")) + downloadEunomiaData() +} +``` + +For this example we'll use the Eunomia synthetic data from the CDMConnector package. + +```{r} +con <- DBI::dbConnect(duckdb::duckdb(), dbdir = eunomia_dir()) +cdm <- cdm_from_con(con, cdm_schema = "main", + write_schema = c(prefix = "my_study_", schema = "main")) +``` + +Let's start by creating two drug cohorts, one for users of diclofenac and another for users of acetaminophen. + +```{r} +cdm$medications <- conceptCohort(cdm = cdm, + conceptSet = list("diclofenac" = 1124300, + "acetaminophen" = 1127433), + name = "medications") +cohortCount(cdm$medications) +``` + +```{r} +cdm$medications_sample <- sampleCohorts(cdm$medications,cohortId = 1, n = 100, name = "medications_sample") + +cohortCount(cdm$medications_sample) ```