Skip to content

Commit

Permalink
Merge pull request #323 from OHDSI/fix_sampleCohorts_issue
Browse files Browse the repository at this point in the history
Fix sample cohorts issue
  • Loading branch information
edward-burn authored Sep 23, 2024
2 parents bbe0b4a + 50b26b6 commit 01d8154
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
2 changes: 1 addition & 1 deletion R/sampleCohorts.R
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#'
Expand Down
7 changes: 4 additions & 3 deletions man/sampleCohorts.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

47 changes: 45 additions & 2 deletions vignettes/a07_filter_cohorts.Rmd
Original file line number Diff line number Diff line change
@@ -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}
---
Expand All @@ -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)
```

0 comments on commit 01d8154

Please sign in to comment.