From 20f016ca1cd948df534683d571b9fafadd374158 Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Wed, 27 Dec 2023 16:42:50 +0000 Subject: [PATCH 1/6] updates --- NAMESPACE | 2 +- ...onCohorts.R => generateIntersectCohorts.R} | 4 +- R/generateUnionCohortSet.R | 4 + R/requireCohortIntersectFlag.R | 31 +++++- R/requireDateRange.R | 20 +++- R/requireDemographics.R | 48 +++++++- R/restrictToFirstEntry.R | 9 +- README.Rmd | 2 +- ...rtSet.Rd => generateIntersectCohortSet.Rd} | 10 +- man/getIdentifier.Rd | 2 +- man/joinOverlap.Rd | 2 +- man/requireAge.Rd | 12 ++ man/requireCohortIntersectFlag.Rd | 18 ++- man/requireDemographics.Rd | 15 +++ man/requireFutureObservation.Rd | 12 ++ man/requireInDateRange.Rd | 8 ++ man/requirePriorObservation.Rd | 12 ++ man/requireSex.Rd | 11 ++ man/splitOverlap.Rd | 2 +- man/trimToDateRange.Rd | 15 +++ ...orts.R => test-generateIntersectCohorts.R} | 10 +- tests/testthat/test-generateUnionCohortSet.R | 3 + .../test-requireCohortIntersectFlag.R | 25 +++++ .../a02_applying_cohort_restrictions.Rmd | 103 +++++++++++++++++- 24 files changed, 343 insertions(+), 37 deletions(-) rename R/{generateCombinationCohorts.R => generateIntersectCohorts.R} (99%) create mode 100644 R/generateUnionCohortSet.R rename man/{generateCombinationCohortSet.Rd => generateIntersectCohortSet.Rd} (84%) rename tests/testthat/{test-generateCombinationCohorts.R => test-generateIntersectCohorts.R} (96%) create mode 100644 tests/testthat/test-generateUnionCohortSet.R diff --git a/NAMESPACE b/NAMESPACE index c84a6a8c..8788c8b1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,6 +1,6 @@ # Generated by roxygen2: do not edit by hand -export(generateCombinationCohortSet) +export(generateIntersectCohortSet) export(generateMatchedCohortSet) export(getIdentifier) export(joinOverlap) diff --git a/R/generateCombinationCohorts.R b/R/generateIntersectCohorts.R similarity index 99% rename from R/generateCombinationCohorts.R rename to R/generateIntersectCohorts.R index 6c451c72..3164649c 100644 --- a/R/generateCombinationCohorts.R +++ b/R/generateIntersectCohorts.R @@ -20,7 +20,7 @@ #' #' cdm <- mockPatientProfiles() #' -#' cdm <- generateCombinationCohortSet( +#' cdm <- generateIntersectCohortSet( #' cdm = cdm, #' name = "cohort3", #' targetCohortName = "cohort2" @@ -32,7 +32,7 @@ #' #' } -generateCombinationCohortSet <- function(cdm, +generateIntersectCohortSet <- function(cdm, name, targetCohortName, targetCohortId = NULL, diff --git a/R/generateUnionCohortSet.R b/R/generateUnionCohortSet.R new file mode 100644 index 00000000..9d1d3151 --- /dev/null +++ b/R/generateUnionCohortSet.R @@ -0,0 +1,4 @@ + +generateUnionCohortSet <- function(){ + +} diff --git a/R/requireCohortIntersectFlag.R b/R/requireCohortIntersectFlag.R index 14293fa3..4320ee34 100644 --- a/R/requireCohortIntersectFlag.R +++ b/R/requireCohortIntersectFlag.R @@ -11,19 +11,30 @@ #' (in overlap) or on its own (for incidence) #' @param targetEndDate date of reference in cohort table, either for end #' (overlap) or NULL (if incidence) -#' @param window window to consider events of +#' @param window window to consider events over +#' @param negate If set as TRUE, criteria will be applied as exclusion +#' rather than inclusion (i.e. require absence in another cohort) #' #' @return Cohort table with only those in the other cohort kept #' @export #' #' @examples +#' library(DrugUtilisation) +#' library(CohortConstructor) +#' cdm <- mockDrugUtilisation(numberIndividuals = 100) +#' cdm$cohort1 %>% +#' requireCohortIntersectFlag(targetCohortTable = "cohort2", +#' targetCohortId = 1, +#' indexDate = "cohort_start_date", +#' window = c(-Inf, 0)) requireCohortIntersectFlag <- function(x, targetCohortTable, targetCohortId = NULL, indexDate = "cohort_start_date", targetStartDate = "cohort_start_date", targetEndDate = "cohort_end_date", - window = list(c(0, Inf))){ + window = list(c(0, Inf)), + negate = FALSE){ cols <- unique(c("cohort_definition_id", "subject_id", "cohort_start_date", "cohort_end_date", @@ -67,9 +78,19 @@ subsetCohort <- x %>% targetEndDate = targetEndDate, window = window, nameStyle = "intersect_cohort" - ) %>% - dplyr::filter(.data$intersect_cohort == 1) %>% - dplyr::select(!"intersect_cohort") + ) + +if(isFALSE(negate)){ + subsetCohort <- subsetCohort %>% + dplyr::filter(.data$intersect_cohort == 1) %>% + dplyr::select(!"intersect_cohort") +} else { + # ie require absence instead of presence + subsetCohort <- subsetCohort %>% + dplyr::filter(.data$intersect_cohort != 1) %>% + dplyr::select(!"intersect_cohort") +} + x %>% dplyr::inner_join(subsetCohort, diff --git a/R/requireDateRange.R b/R/requireDateRange.R index c4c2c2b2..5a87c4c9 100644 --- a/R/requireDateRange.R +++ b/R/requireDateRange.R @@ -10,6 +10,12 @@ #' @export #' #' @examples +#' library(DrugUtilisation) +#' library(CohortConstructor) +#' cdm <- mockDrugUtilisation(numberIndividuals = 100) +#' cdm$cohort1 %>% +#' requireInDateRange(indexDate = "cohort_start_date", +#' dateRange = as.Date(c("2010-01-01", "2019-01-01"))) requireInDateRange <- function(cohort, indexDate = "cohort_start_date", dateRange = as.Date(c(NA, NA))) { @@ -38,10 +44,20 @@ requireInDateRange <- function(cohort, #' @param dateRange A window of time during which the index date must have #' been observed #' -#' @return +#' @return The cohort table with record timings updated to only be within the +#' date range. Any records with all time outside of the range will have +#' been dropped. #' @export #' #' @examples +#' library(DrugUtilisation) +#' library(CohortConstructor) +#' cdm <- mockDrugUtilisation(numberIndividuals = 100) +#' cdm$cohort1 %>% +#' trimToDateRange(startDate = "cohort_start_date", +#' endDate = "cohort_end_date", +#' dateRange = as.Date(c("2015-01-01", +#' "2015-12-31"))) trimToDateRange <- function(cohort, startDate = "cohort_start_date", endDate = "cohort_end_date", @@ -93,6 +109,8 @@ trimToDateRange <- function(cohort, endDate, " <= ", dateRange[2] )) + + cohort } trimStartDate <- function(cohort, diff --git a/R/requireDemographics.R b/R/requireDemographics.R index d98a2654..ae86e866 100644 --- a/R/requireDemographics.R +++ b/R/requireDemographics.R @@ -13,10 +13,20 @@ #' @param minFutureObservation A minimum number of future observation days in #' the database. #' -#' @return +#' @return The cohort table with only records for individuals satisfying the +#' demographic requirements #' @export #' #' @examples +#' library(DrugUtilisation) +#' library(CohortConstructor) +#' cdm <- mockDrugUtilisation(numberIndividuals = 100) +#' cdm$cohort1 %>% +#' requireDemographics(indexDate = "cohort_start_date", +#' ageRange = list(c(18, 65)), +#' sex = "Female", +#' minPriorObservation = 365) +#' requireDemographics <- function(cohort, indexDate = "cohort_start_date", ageRange = list(c(0, 150)), @@ -63,10 +73,17 @@ requireDemographics <- function(cohort, #' demographics characteristics on which to restrict on. #' @param ageRange A list of minimum and maximum age #' -#' @return +#' @return The cohort table with only records for individuals satisfying the +#' age requirement #' @export #' #' @examples +#' library(DrugUtilisation) +#' library(CohortConstructor) +#' cdm <- mockDrugUtilisation(numberIndividuals = 100) +#' cdm$cohort1 %>% +#' requireAge(indexDate = "cohort_start_date", +#' ageRange = list(c(18, 65))) requireAge <- function(cohort, indexDate = "cohort_start_date", ageRange = list(c(0, 150))) { @@ -94,10 +111,16 @@ requireAge <- function(cohort, #' @param sex Can be "Both", "Male" or "Female". If one of the latter, only #' those with that sex will be included. #' -#' @return +#' @return The cohort table with only records for individuals satisfying the +#' sex requirement #' @export #' #' @examples +#' library(DrugUtilisation) +#' library(CohortConstructor) +#' cdm <- mockDrugUtilisation(numberIndividuals = 100) +#' cdm$cohort1 %>% +#' requireSex(sex = "Female") requireSex <- function(cohort, sex = c("Both")) { cohort <- demographicsFilter( @@ -127,10 +150,17 @@ requireSex <- function(cohort, #' @param minPriorObservation A mimimum number of prior observation days in #' the database. #' -#' @return +#' @return The cohort table with only records for individuals satisfying the +#' prior observation requirement #' @export #' #' @examples +#' library(DrugUtilisation) +#' library(CohortConstructor) +#' cdm <- mockDrugUtilisation(numberIndividuals = 100) +#' cdm$cohort1 %>% +#' requirePriorObservation(indexDate = "cohort_start_date", +#' minPriorObservation = 365) requirePriorObservation <- function(cohort, indexDate = "cohort_start_date", minPriorObservation = 0) { @@ -160,10 +190,18 @@ requirePriorObservation <- function(cohort, #' @param minFutureObservation A minimum number of future observation days in #' the database. #' -#' @return +#' @return The cohort table with only records for individuals satisfying the +#' future observation requirement +#' #' @export #' #' @examples +#' library(DrugUtilisation) +#' library(CohortConstructor) +#' cdm <- mockDrugUtilisation(numberIndividuals = 100) +#' cdm$cohort1 %>% +#' requireFutureObservation(indexDate = "cohort_start_date", +#' minFutureObservation = 30) requireFutureObservation <- function(cohort, indexDate = "cohort_start_date", minFutureObservation = 0) { diff --git a/R/restrictToFirstEntry.R b/R/restrictToFirstEntry.R index 398076c0..45d8f8dc 100644 --- a/R/restrictToFirstEntry.R +++ b/R/restrictToFirstEntry.R @@ -30,10 +30,11 @@ restrictToFirstEntry <- function(cohort, #restrict to first entry indexDateSym <- rlang::sym(indexDate) - cohort <- cohort |> dplyr::group_by(.data$subject_id,.data$cohort_definition_id) |> - dplyr::filter(!!indexDateSym == min(!!indexDateSym, na.rm = TRUE)) |> - dplyr::ungroup() |> - CDMConnector::recordCohortAttrition("restrict to first entry") + cohort <- cohort %>% + dplyr::group_by(.data$subject_id,.data$cohort_definition_id) %>% + dplyr::filter(!!indexDateSym == min(!!indexDateSym, na.rm = TRUE)) %>% + dplyr::ungroup() %>% + CDMConnector::recordCohortAttrition("Restricted to first entry") return(cohort) diff --git a/README.Rmd b/README.Rmd index c7aad010..f12908d6 100644 --- a/README.Rmd +++ b/README.Rmd @@ -130,7 +130,7 @@ Both diclofenac and acetaminophen Generate a combination cohort. ```{r} -cdm <- generateCombinationCohortSet(cdm = cdm, +cdm <- generateIntersectCohortSet(cdm = cdm, name = "combinations", targetCohortName = "medications") diff --git a/man/generateCombinationCohortSet.Rd b/man/generateIntersectCohortSet.Rd similarity index 84% rename from man/generateCombinationCohortSet.Rd rename to man/generateIntersectCohortSet.Rd index e828ea78..510a49d0 100644 --- a/man/generateCombinationCohortSet.Rd +++ b/man/generateIntersectCohortSet.Rd @@ -1,11 +1,11 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/generateCombinationCohorts.R -\name{generateCombinationCohortSet} -\alias{generateCombinationCohortSet} +% Please edit documentation in R/generateIntersectCohorts.R +\name{generateIntersectCohortSet} +\alias{generateIntersectCohortSet} \title{Generate a combination cohort set between the intersection of different cohorts.} \usage{ -generateCombinationCohortSet( +generateIntersectCohortSet( cdm, name, targetCohortName, @@ -43,7 +43,7 @@ library(PatientProfiles) cdm <- mockPatientProfiles() -cdm <- generateCombinationCohortSet( +cdm <- generateIntersectCohortSet( cdm = cdm, name = "cohort3", targetCohortName = "cohort2" diff --git a/man/getIdentifier.Rd b/man/getIdentifier.Rd index 90a9e1de..aad6b460 100644 --- a/man/getIdentifier.Rd +++ b/man/getIdentifier.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/generateCombinationCohorts.R +% Please edit documentation in R/generateIntersectCohorts.R \name{getIdentifier} \alias{getIdentifier} \title{Get ramdon identifies not present in a table based on a prefix.} diff --git a/man/joinOverlap.Rd b/man/joinOverlap.Rd index 6ebfc161..27a4b4a6 100644 --- a/man/joinOverlap.Rd +++ b/man/joinOverlap.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/generateCombinationCohorts.R +% Please edit documentation in R/generateIntersectCohorts.R \name{joinOverlap} \alias{joinOverlap} \title{Join overlapping periods in single periods.} diff --git a/man/requireAge.Rd b/man/requireAge.Rd index 3246a638..2c43d0c8 100644 --- a/man/requireAge.Rd +++ b/man/requireAge.Rd @@ -14,6 +14,18 @@ demographics characteristics on which to restrict on.} \item{ageRange}{A list of minimum and maximum age} } +\value{ +The cohort table with only records for individuals satisfying the +age requirement +} \description{ Restrict cohort on age } +\examples{ +library(DrugUtilisation) +library(CohortConstructor) +cdm <- mockDrugUtilisation(numberIndividuals = 100) +cdm$cohort1 \%>\% + requireAge(indexDate = "cohort_start_date", + ageRange = list(c(18, 65))) +} diff --git a/man/requireCohortIntersectFlag.Rd b/man/requireCohortIntersectFlag.Rd index df833903..4d84c502 100644 --- a/man/requireCohortIntersectFlag.Rd +++ b/man/requireCohortIntersectFlag.Rd @@ -11,7 +11,8 @@ requireCohortIntersectFlag( indexDate = "cohort_start_date", targetStartDate = "cohort_start_date", targetEndDate = "cohort_end_date", - window = list(c(0, Inf)) + window = list(c(0, Inf)), + negate = FALSE ) } \arguments{ @@ -30,7 +31,10 @@ intersection.} \item{targetEndDate}{date of reference in cohort table, either for end (overlap) or NULL (if incidence)} -\item{window}{window to consider events of} +\item{window}{window to consider events over} + +\item{negate}{If set as TRUE, criteria will be applied as exclusion +rather than inclusion (i.e. require absence in another cohort)} } \value{ Cohort table with only those in the other cohort kept @@ -38,3 +42,13 @@ Cohort table with only those in the other cohort kept \description{ Require cohort subjects are present in another cohort } +\examples{ +library(DrugUtilisation) +library(CohortConstructor) +cdm <- mockDrugUtilisation(numberIndividuals = 100) +cdm$cohort1 \%>\% + requireCohortIntersectFlag(targetCohortTable = "cohort2", + targetCohortId = 1, + indexDate = "cohort_start_date", + window = c(-Inf, 0)) +} diff --git a/man/requireDemographics.Rd b/man/requireDemographics.Rd index 7aa7fed8..bca7b3c5 100644 --- a/man/requireDemographics.Rd +++ b/man/requireDemographics.Rd @@ -30,6 +30,21 @@ the database.} \item{minFutureObservation}{A minimum number of future observation days in the database.} } +\value{ +The cohort table with only records for individuals satisfying the +demographic requirements +} \description{ Restrict cohort on patient demographics } +\examples{ +library(DrugUtilisation) +library(CohortConstructor) +cdm <- mockDrugUtilisation(numberIndividuals = 100) +cdm$cohort1 \%>\% + requireDemographics(indexDate = "cohort_start_date", + ageRange = list(c(18, 65)), + sex = "Female", + minPriorObservation = 365) + +} diff --git a/man/requireFutureObservation.Rd b/man/requireFutureObservation.Rd index ecd47b24..5c789e31 100644 --- a/man/requireFutureObservation.Rd +++ b/man/requireFutureObservation.Rd @@ -19,6 +19,18 @@ demographics characteristics on which to restrict on.} \item{minFutureObservation}{A minimum number of future observation days in the database.} } +\value{ +The cohort table with only records for individuals satisfying the +future observation requirement +} \description{ Restrict cohort on future observation } +\examples{ +library(DrugUtilisation) +library(CohortConstructor) +cdm <- mockDrugUtilisation(numberIndividuals = 100) +cdm$cohort1 \%>\% + requireFutureObservation(indexDate = "cohort_start_date", + minFutureObservation = 30) +} diff --git a/man/requireInDateRange.Rd b/man/requireInDateRange.Rd index d03705cf..0adcac70 100644 --- a/man/requireInDateRange.Rd +++ b/man/requireInDateRange.Rd @@ -25,3 +25,11 @@ dropped \description{ Require that an index date is within a date range } +\examples{ +library(DrugUtilisation) +library(CohortConstructor) +cdm <- mockDrugUtilisation(numberIndividuals = 100) +cdm$cohort1 \%>\% + requireInDateRange(indexDate = "cohort_start_date", + dateRange = as.Date(c("2010-01-01", "2019-01-01"))) +} diff --git a/man/requirePriorObservation.Rd b/man/requirePriorObservation.Rd index 143cc8ec..cda36a45 100644 --- a/man/requirePriorObservation.Rd +++ b/man/requirePriorObservation.Rd @@ -19,6 +19,18 @@ demographics characteristics on which to restrict on.} \item{minPriorObservation}{A mimimum number of prior observation days in the database.} } +\value{ +The cohort table with only records for individuals satisfying the +prior observation requirement +} \description{ Restrict cohort on prior observation } +\examples{ +library(DrugUtilisation) +library(CohortConstructor) +cdm <- mockDrugUtilisation(numberIndividuals = 100) +cdm$cohort1 \%>\% + requirePriorObservation(indexDate = "cohort_start_date", + minPriorObservation = 365) +} diff --git a/man/requireSex.Rd b/man/requireSex.Rd index a98434d9..3eda634d 100644 --- a/man/requireSex.Rd +++ b/man/requireSex.Rd @@ -12,6 +12,17 @@ requireSex(cohort, sex = c("Both")) \item{sex}{Can be "Both", "Male" or "Female". If one of the latter, only those with that sex will be included.} } +\value{ +The cohort table with only records for individuals satisfying the +sex requirement +} \description{ Restrict cohort on sex } +\examples{ +library(DrugUtilisation) +library(CohortConstructor) +cdm <- mockDrugUtilisation(numberIndividuals = 100) +cdm$cohort1 \%>\% + requireSex(sex = "Female") +} diff --git a/man/splitOverlap.Rd b/man/splitOverlap.Rd index a34f8243..1fb7506d 100644 --- a/man/splitOverlap.Rd +++ b/man/splitOverlap.Rd @@ -1,5 +1,5 @@ % Generated by roxygen2: do not edit by hand -% Please edit documentation in R/generateCombinationCohorts.R +% Please edit documentation in R/generateIntersectCohorts.R \name{splitOverlap} \alias{splitOverlap} \title{To split overlaping periods in non overlaping period.} diff --git a/man/trimToDateRange.Rd b/man/trimToDateRange.Rd index 59cb6f35..ae32991d 100644 --- a/man/trimToDateRange.Rd +++ b/man/trimToDateRange.Rd @@ -21,6 +21,21 @@ trimToDateRange( \item{dateRange}{A window of time during which the index date must have been observed} } +\value{ +The cohort table with record timings updated to only be within the +date range. Any records with all time outside of the range will have +been dropped. +} \description{ Trim cohort dates to be within a date range } +\examples{ +library(DrugUtilisation) +library(CohortConstructor) +cdm <- mockDrugUtilisation(numberIndividuals = 100) +cdm$cohort1 \%>\% + trimToDateRange(startDate = "cohort_start_date", + endDate = "cohort_end_date", + dateRange = as.Date(c("2015-01-01", + "2015-12-31"))) +} diff --git a/tests/testthat/test-generateCombinationCohorts.R b/tests/testthat/test-generateIntersectCohorts.R similarity index 96% rename from tests/testthat/test-generateCombinationCohorts.R rename to tests/testthat/test-generateIntersectCohorts.R index cf8c07dd..9f0d8c79 100644 --- a/tests/testthat/test-generateCombinationCohorts.R +++ b/tests/testthat/test-generateIntersectCohorts.R @@ -123,7 +123,7 @@ test_that("splitOverlap", { DBI::dbDisconnect(db, shutdown = TRUE) }) -test_that("generateCombinationCohortSet", { +test_that("generateIntersectCohortSet", { cohort <- dplyr::tibble( cohort_definition_id = c(1, 2, 3, 1, 2, 3, 1, 2), subject_id = c(1, 1, 1, 2, 3, 3, 4, 4), @@ -154,7 +154,7 @@ test_that("generateCombinationCohortSet", { ) # mutually exclusive - expect_no_error(cdm <- generateCombinationCohortSet( + expect_no_error(cdm <- generateIntersectCohortSet( cdm = cdm, name = "cohort2", targetCohortName = "cohort1", mutuallyExclusive = TRUE )) @@ -167,7 +167,7 @@ test_that("generateCombinationCohortSet", { )) # not mutually exclusive - expect_no_error(cdm <- generateCombinationCohortSet( + expect_no_error(cdm <- generateIntersectCohortSet( cdm = cdm, name = "cohort3", targetCohortName = "cohort1", mutuallyExclusive = FALSE )) @@ -180,7 +180,7 @@ test_that("generateCombinationCohortSet", { )) # not enough cohorts provided - expect_warning(cdm <- generateCombinationCohortSet( + expect_warning(cdm <- generateIntersectCohortSet( cdm = cdm, name = "cohort4", targetCohortName = "cohort1", targetCohortId = 1 )) @@ -219,7 +219,7 @@ test_that("only return comb", { observation_period = observation_period, person = person, cohort1 = cohort ) - cdm <- generateCombinationCohortSet( + cdm <- generateIntersectCohortSet( cdm = cdm, name = "cohort2", targetCohortName = "cohort1", mutuallyExclusive = FALSE, returnOnlyComb = TRUE ) diff --git a/tests/testthat/test-generateUnionCohortSet.R b/tests/testthat/test-generateUnionCohortSet.R new file mode 100644 index 00000000..8849056e --- /dev/null +++ b/tests/testthat/test-generateUnionCohortSet.R @@ -0,0 +1,3 @@ +test_that("multiplication works", { + expect_equal(2 * 2, 4) +}) diff --git a/tests/testthat/test-requireCohortIntersectFlag.R b/tests/testthat/test-requireCohortIntersectFlag.R index 1a2cc90d..5e7b6099 100644 --- a/tests/testthat/test-requireCohortIntersectFlag.R +++ b/tests/testthat/test-requireCohortIntersectFlag.R @@ -54,4 +54,29 @@ test_that("requiring presence in another cohort", { }) +test_that("requiring absence in another cohort", { +cdm <- PatientProfiles::mockPatientProfiles(patient_size = 100, + drug_exposure_size = 100) + +cdm$cohort3_inclusion <- requireCohortIntersectFlag(x = cdm$cohort1, + targetCohortTable = "cohort2", + targetCohortId = 1, + window = c(-Inf, Inf)) +cdm$cohort3_exclusion <- requireCohortIntersectFlag(x = cdm$cohort1, + targetCohortTable = "cohort2", + targetCohortId = 1, + window = c(-Inf, Inf), + negate = TRUE) + +in_both <- intersect(cdm$cohort3_inclusion %>% + dplyr::pull("subject_id") %>% + unique(), + cdm$cohort3_exclusion %>% + dplyr::pull("subject_id") %>% + unique()) +expect_true(length(in_both) == 0) + +CDMConnector::cdm_disconnect(cdm) + +}) diff --git a/vignettes/a02_applying_cohort_restrictions.Rmd b/vignettes/a02_applying_cohort_restrictions.Rmd index 2bd24072..ca5829bf 100644 --- a/vignettes/a02_applying_cohort_restrictions.Rmd +++ b/vignettes/a02_applying_cohort_restrictions.Rmd @@ -1,5 +1,5 @@ --- -title: "a02_applying_cohort_restrictions" +title: "Applying cohort restrictions" output: rmarkdown::html_vignette vignette: > %\VignetteIndexEntry{a02_applying_cohort_restrictions} @@ -9,11 +9,108 @@ vignette: > ```{r, include = FALSE} knitr::opts_chunk$set( - collapse = TRUE, + collapse = TRUE, + message = FALSE, + warning = FALSE, comment = "#>" ) ``` -```{r setup} +For this example we'll use the Eunomia synthetic data from the CDMConnector package. +```{r} +library(CDMConnector) +library(DrugUtilisation) library(CohortConstructor) +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. We'll use the `generateDrugUtilisationCohortSet()` from the DrugUtilisation package so that we can specify a gap era when creating the cohort. +```{r} +cdm <- generateDrugUtilisationCohortSet(cdm = cdm, + name = "medications", + conceptSet = list("diclofenac" = 1124300, + "acetaminophen" = 1127433), + gapEra = 7) +cohortCount(cdm$medications) +``` + +As well as our medication cohorts, let's also make another cohort containing individuals with a record of a GI bleed. For this cohort we can use `generateConceptCohortSet()` from the CDMConnector package. Later we'll use this cohort when specifying inclusion/ exclusion criteria. +```{r} +cdm <- generateConceptCohortSet(cdm = cdm, + name = "gi_bleed", + conceptSet = list("gi_bleed" = 192671)) +``` + +## Keep only the first record per person +Individuals can contribute multiple records per cohort. However now we'll keep only their earliest cohort entry of the remaining records using `restrictToFirstEntry()` from CohortConstructor. We can see that after this we have one record per person for each cohort. +```{r} +cdm$medications <- cdm$medications %>% + restrictToFirstEntry(indexDate = "cohort_start_date") + +cohortCount(cdm$medications) +``` + +Note, applying this criteria later after applying other criteria would result in a different result. Here we're requiring that individuals meet inclusion criteria at the time of their first use of diclofenac or acetaminophen. + +## Applying restrictions on patient demographics +Using `requireDemographics()` we'll require that individuals in our medications cohort are female and, relative to their cohort start date, are between 18 and 85 with at least 30 days of prior observation time in the database. +```{r} +cdm$medications <- cdm$medications %>% + requireDemographics(indexDate = "cohort_start_date", + ageRange = list(c(18, 85)), + sex = "Female", + minPriorObservation = 30) +``` + +We can then see how many people have people have been excluded based on these demographic requirements. +```{r} +cohort_attrition(cdm$medications) %>% + dplyr::filter(reason == "Demographic requirements") %>% + dplyr::glimpse() +``` + + +## Restrictions on calendar dates +Next we can use `requireInDateRange()` to keep only those records where cohort entry was between a particular date range. +```{r} +cdm$medications <- cdm$medications %>% + requireInDateRange(indexDate = "cohort_start_date", + dateRange = as.Date(c("2000-01-01", "2015-01-01"))) +``` + +Again, we can track cohort attrition +```{r} +cohort_attrition(cdm$medications) %>% + dplyr::filter(reason == "cohort_start_date between 2000-01-01 and 2015-01-01") %>% + dplyr::glimpse() +``` + + +## Restrictions on cohort presence +We could require that individuals in our medication cohorts have a history of GI bleed. To do this we can use the `requireCohortIntersectFlag()` function. + +```{r} +cdm$medications_gi_bleed <- cdm$medications %>% + requireCohortIntersectFlag(targetCohortTable = "gi_bleed", + targetCohortId = 1, + indexDate = "cohort_start_date", + window = c(-Inf, 0)) +cohort_count(cdm$medications_gi_bleed) +``` + +Instead of requiring that individuals have history of GI bleed, we could instead require that they are don't have any history of it. In this case we can again use the `requireCohortIntersectFlag()` function, but this time set the negate argument to FALSE to require individuals' absence in this other cohort rather than their presence in it. + +```{r} +cdm$medications_no_gi_bleed <- cdm$medications %>% + requireCohortIntersectFlag(targetCohortTable = "gi_bleed", + targetCohortId = 1, + indexDate = "cohort_start_date", + window = c(-Inf, 0), + negate = TRUE) +cohort_count(cdm$medications_no_gi_bleed) +``` + + + From f634d22b806e2d28e3d47a286bccb1cc968349b8 Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Wed, 27 Dec 2023 16:49:17 +0000 Subject: [PATCH 2/6] spelling and eunomia --- R/generateIntersectCohorts.R | 6 +++--- R/requireDemographics.R | 4 ++-- README.Rmd | 2 -- README.md | 5 +---- inst/WORDLIST | 17 +++++++++++++++++ man/getIdentifier.Rd | 4 ++-- man/joinOverlap.Rd | 2 +- man/requireDemographics.Rd | 2 +- man/requirePriorObservation.Rd | 2 +- man/splitOverlap.Rd | 2 +- vignettes/a02_applying_cohort_restrictions.Rmd | 4 ++++ 11 files changed, 33 insertions(+), 17 deletions(-) create mode 100644 inst/WORDLIST diff --git a/R/generateIntersectCohorts.R b/R/generateIntersectCohorts.R index 3164649c..2037a215 100644 --- a/R/generateIntersectCohorts.R +++ b/R/generateIntersectCohorts.R @@ -178,7 +178,7 @@ generateIntersectCohortSet <- function(cdm, #' @export #' #' @return Table in the cdm with start, end and by as columns. Periods are not -#' going to overlpa between each other. +#' going to overlap between each other. #' splitOverlap <- function(x, start = "cohort_start_date", @@ -244,7 +244,7 @@ splitOverlap <- function(x, #' @export #' #' @return Table in the cdm with start, end and by as columns. Periods are not -#' going to overlpa between each other. +#' going to overlap between each other. #' joinOverlap <- function(x, start = "cohort_start_date", @@ -302,7 +302,7 @@ joinOverlap <- function(x, CDMConnector::computeQuery() } -#' Get ramdon identifies not present in a table based on a prefix. +#' Get random identifiers not present in a table based on a prefix. #' #' @param x Table. #' @param len Number of identifiers. diff --git a/R/requireDemographics.R b/R/requireDemographics.R index ae86e866..a9b35546 100644 --- a/R/requireDemographics.R +++ b/R/requireDemographics.R @@ -8,7 +8,7 @@ #' @param ageRange A list of minimum and maximum age #' @param sex Can be "Both", "Male" or "Female". If one of the latter, only #' those with that sex will be included. -#' @param minPriorObservation A mimimum number of prior observation days in +#' @param minPriorObservation A minimum number of prior observation days in #' the database. #' @param minFutureObservation A minimum number of future observation days in #' the database. @@ -147,7 +147,7 @@ requireSex <- function(cohort, #' @param cohort A cohort table in a cdm reference #' @param indexDate Variable in cohort that contains the date to compute the #' demographics characteristics on which to restrict on. -#' @param minPriorObservation A mimimum number of prior observation days in +#' @param minPriorObservation A minimum number of prior observation days in #' the database. #' #' @return The cohort table with only records for individuals satisfying the diff --git a/README.Rmd b/README.Rmd index f12908d6..1956fdb9 100644 --- a/README.Rmd +++ b/README.Rmd @@ -16,8 +16,6 @@ knitr::opts_chunk$set( # CohortConstructor -[![CRAN status](https://www.r-pkg.org/badges/version/CohortConstructor)](https://CRAN.R-project.org/package=CohortConstructor) -[![codecov.io](https://codecov.io/github/oxford-pharmacoepi/CohortConstructor/coverage.svg?branch=main)](https://app.codecov.io/github/oxford-pharmacoepi/CohortConstructor?branch=main) [![R-CMD-check](https://github.com/oxford-pharmacoepi/CohortConstructor/workflows/R-CMD-check/badge.svg)](https://github.com/oxford-pharmacoepi/CohortConstructor/actions) [![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://lifecycle.r-lib.org/articles/stages.html#experimental) diff --git a/README.md b/README.md index bf14e598..7d18db58 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,6 @@ -[![CRAN -status](https://www.r-pkg.org/badges/version/CohortConstructor)](https://CRAN.R-project.org/package=CohortConstructor) -[![codecov.io](https://codecov.io/github/oxford-pharmacoepi/CohortConstructor/coverage.svg?branch=main)](https://app.codecov.io/github/oxford-pharmacoepi/CohortConstructor?branch=main) [![R-CMD-check](https://github.com/oxford-pharmacoepi/CohortConstructor/workflows/R-CMD-check/badge.svg)](https://github.com/oxford-pharmacoepi/CohortConstructor/actions) [![Lifecycle:Experimental](https://img.shields.io/badge/Lifecycle-Experimental-339999)](https://lifecycle.r-lib.org/articles/stages.html#experimental) @@ -214,7 +211,7 @@ Both diclofenac and acetaminophen Generate a combination cohort. ``` r -cdm <- generateCombinationCohortSet(cdm = cdm, +cdm <- generateIntersectCohortSet(cdm = cdm, name = "combinations", targetCohortName = "medications") diff --git a/inst/WORDLIST b/inst/WORDLIST new file mode 100644 index 00000000..d47d6a85 --- /dev/null +++ b/inst/WORDLIST @@ -0,0 +1,17 @@ +CDMConnector +CMD +DrugUtilisation +Eunomia +Lifecycle +OMOP +ORCID +cdm +codecov +diclofenac +generateDrugUtilisationCohortSet +indexDate +individuals’ +io +matchSex +matchYearOfBirth +overlaping diff --git a/man/getIdentifier.Rd b/man/getIdentifier.Rd index aad6b460..ac152dab 100644 --- a/man/getIdentifier.Rd +++ b/man/getIdentifier.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/generateIntersectCohorts.R \name{getIdentifier} \alias{getIdentifier} -\title{Get ramdon identifies not present in a table based on a prefix.} +\title{Get random identifiers not present in a table based on a prefix.} \usage{ getIdentifier(x, len = 1, prefix = "", nchar = 5) } @@ -19,5 +19,5 @@ getIdentifier(x, len = 1, prefix = "", nchar = 5) Character vector of identifiers not present in x. } \description{ -Get ramdon identifies not present in a table based on a prefix. +Get random identifiers not present in a table based on a prefix. } diff --git a/man/joinOverlap.Rd b/man/joinOverlap.Rd index 27a4b4a6..1455b8cd 100644 --- a/man/joinOverlap.Rd +++ b/man/joinOverlap.Rd @@ -25,7 +25,7 @@ joinOverlap( } \value{ Table in the cdm with start, end and by as columns. Periods are not -going to overlpa between each other. +going to overlap between each other. } \description{ Join overlapping periods in single periods. diff --git a/man/requireDemographics.Rd b/man/requireDemographics.Rd index bca7b3c5..99e7854c 100644 --- a/man/requireDemographics.Rd +++ b/man/requireDemographics.Rd @@ -24,7 +24,7 @@ demographics characteristics on which to restrict on.} \item{sex}{Can be "Both", "Male" or "Female". If one of the latter, only those with that sex will be included.} -\item{minPriorObservation}{A mimimum number of prior observation days in +\item{minPriorObservation}{A minimum number of prior observation days in the database.} \item{minFutureObservation}{A minimum number of future observation days in diff --git a/man/requirePriorObservation.Rd b/man/requirePriorObservation.Rd index cda36a45..88d0ccd8 100644 --- a/man/requirePriorObservation.Rd +++ b/man/requirePriorObservation.Rd @@ -16,7 +16,7 @@ requirePriorObservation( \item{indexDate}{Variable in cohort that contains the date to compute the demographics characteristics on which to restrict on.} -\item{minPriorObservation}{A mimimum number of prior observation days in +\item{minPriorObservation}{A minimum number of prior observation days in the database.} } \value{ diff --git a/man/splitOverlap.Rd b/man/splitOverlap.Rd index 1fb7506d..2bf4e499 100644 --- a/man/splitOverlap.Rd +++ b/man/splitOverlap.Rd @@ -22,7 +22,7 @@ splitOverlap( } \value{ Table in the cdm with start, end and by as columns. Periods are not -going to overlpa between each other. +going to overlap between each other. } \description{ To split overlaping periods in non overlaping period. diff --git a/vignettes/a02_applying_cohort_restrictions.Rmd b/vignettes/a02_applying_cohort_restrictions.Rmd index ca5829bf..9d8776c7 100644 --- a/vignettes/a02_applying_cohort_restrictions.Rmd +++ b/vignettes/a02_applying_cohort_restrictions.Rmd @@ -14,6 +14,10 @@ knitr::opts_chunk$set( warning = FALSE, comment = "#>" ) + +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")) +if (!eunomia_is_available()) downloadEunomiaData() ``` For this example we'll use the Eunomia synthetic data from the CDMConnector package. From 57b89793af99255c92df63e9763b7d6666b89dd3 Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:01:38 +0000 Subject: [PATCH 3/6] updates --- DESCRIPTION | 13 ++++++++----- man/CohortConstructor-package.Rd | 5 +++-- vignettes/a02_applying_cohort_restrictions.Rmd | 10 ++++++---- 3 files changed, 17 insertions(+), 11 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 3c9a4773..236cdb3f 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,14 +1,17 @@ Package: CohortConstructor -Title: Generate Cohorts of Individuals in the OMOP Common Data Model +Title: Work With Cohorts Using a Common Data Model Version: 0.0.1 Authors@R: c( + person("Edward", "Burn", , "edward.burn@ndorms.ox.ac.uk", + role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9286-1128")), person("Marti", "Catala", , "marti.catalasabate@ndorms.ox.ac.uk", role = c("aut"), comment = c(ORCID = "0000-0003-3308-9905")), - person("Edward", "Burn", , "edward.burn@ndorms.ox.ac.uk", - role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9286-1128")) + person("Marta", "Alcalde", , "marta.alcaldeherraiz@ndorms.ox.ac.uk", + role = c("aut"), comment = c(ORCID = "0000-0000-0000-0000")) ) -Description: This package aims to provide functionalities to create cohorts in - the OMOP Common Data Model. +Description: This package aims to provide functionalities to manipulate + and evaluate cohorts in data mapped to the Observational Medical + Outcomes Partnership Common Data Model. License: Apache License (>= 2) Encoding: UTF-8 Roxygen: list(markdown = TRUE) diff --git a/man/CohortConstructor-package.Rd b/man/CohortConstructor-package.Rd index 12200515..4a463da5 100644 --- a/man/CohortConstructor-package.Rd +++ b/man/CohortConstructor-package.Rd @@ -4,9 +4,9 @@ \name{CohortConstructor-package} \alias{CohortConstructor} \alias{CohortConstructor-package} -\title{CohortConstructor: Generate Cohorts of Individuals in the OMOP Common Data Model} +\title{CohortConstructor: Work With Cohorts Using a Common Data Model} \description{ -This package aims to provide functionalities to create cohorts in the OMOP Common Data Model. +This package aims to provide functionalities to manipulate and evaluate cohorts in data mapped to the Observational Medical Outcomes Partnership Common Data Model. } \author{ \strong{Maintainer}: Edward Burn \email{edward.burn@ndorms.ox.ac.uk} (\href{https://orcid.org/0000-0002-9286-1128}{ORCID}) @@ -14,6 +14,7 @@ This package aims to provide functionalities to create cohorts in the OMOP Commo Authors: \itemize{ \item Marti Catala \email{marti.catalasabate@ndorms.ox.ac.uk} (\href{https://orcid.org/0000-0003-3308-9905}{ORCID}) + \item Marta Alcalde \email{marta.alcaldeherraiz@ndorms.ox.ac.uk} (\href{https://orcid.org/0000-0000-0000-0000}{ORCID}) } } diff --git a/vignettes/a02_applying_cohort_restrictions.Rmd b/vignettes/a02_applying_cohort_restrictions.Rmd index 9d8776c7..1b1fa228 100644 --- a/vignettes/a02_applying_cohort_restrictions.Rmd +++ b/vignettes/a02_applying_cohort_restrictions.Rmd @@ -14,10 +14,6 @@ knitr::opts_chunk$set( warning = FALSE, comment = "#>" ) - -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")) -if (!eunomia_is_available()) downloadEunomiaData() ``` For this example we'll use the Eunomia synthetic data from the CDMConnector package. @@ -30,6 +26,12 @@ cdm <- cdm_from_con(con, cdm_schema = "main", write_schema = c(prefix = "my_study_", schema = "main")) ``` +```{r, include = 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")) +if (!eunomia_is_available()) downloadEunomiaData() +``` + Let's start by creating two drug cohorts, one for users of diclofenac and another for users of acetaminophen. We'll use the `generateDrugUtilisationCohortSet()` from the DrugUtilisation package so that we can specify a gap era when creating the cohort. ```{r} cdm <- generateDrugUtilisationCohortSet(cdm = cdm, From 74d43529c131d975bf2d0e1439da7e69f61ea26d Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Wed, 27 Dec 2023 17:06:15 +0000 Subject: [PATCH 4/6] docs --- DESCRIPTION | 4 +++- man/CohortConstructor-package.Rd | 1 + 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/DESCRIPTION b/DESCRIPTION index 236cdb3f..cba81b60 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -7,7 +7,9 @@ Authors@R: c( person("Marti", "Catala", , "marti.catalasabate@ndorms.ox.ac.uk", role = c("aut"), comment = c(ORCID = "0000-0003-3308-9905")), person("Marta", "Alcalde", , "marta.alcaldeherraiz@ndorms.ox.ac.uk", - role = c("aut"), comment = c(ORCID = "0000-0000-0000-0000")) + role = c("aut"), comment = c(ORCID = "0000-0000-0000-0000")), + person("Yuchen", "Guo", email = "yuchen.guo@ndorms.ox.ac.uk", + role = c("aut"), comment = c(ORCID = "0000-0002-0847-4855")) ) Description: This package aims to provide functionalities to manipulate and evaluate cohorts in data mapped to the Observational Medical diff --git a/man/CohortConstructor-package.Rd b/man/CohortConstructor-package.Rd index 4a463da5..bbb21399 100644 --- a/man/CohortConstructor-package.Rd +++ b/man/CohortConstructor-package.Rd @@ -15,6 +15,7 @@ Authors: \itemize{ \item Marti Catala \email{marti.catalasabate@ndorms.ox.ac.uk} (\href{https://orcid.org/0000-0003-3308-9905}{ORCID}) \item Marta Alcalde \email{marta.alcaldeherraiz@ndorms.ox.ac.uk} (\href{https://orcid.org/0000-0000-0000-0000}{ORCID}) + \item Yuchen Guo \email{yuchen.guo@ndorms.ox.ac.uk} (\href{https://orcid.org/0000-0002-0847-4855}{ORCID}) } } From d56c440d1466e05f8ec7c08be1f1574298884464 Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Wed, 27 Dec 2023 20:35:36 +0000 Subject: [PATCH 5/6] eunomia data --- vignettes/a02_applying_cohort_restrictions.Rmd | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/vignettes/a02_applying_cohort_restrictions.Rmd b/vignettes/a02_applying_cohort_restrictions.Rmd index 1b1fa228..cd1f91ec 100644 --- a/vignettes/a02_applying_cohort_restrictions.Rmd +++ b/vignettes/a02_applying_cohort_restrictions.Rmd @@ -27,9 +27,14 @@ cdm <- cdm_from_con(con, cdm_schema = "main", ``` ```{r, include = 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")) -if (!eunomia_is_available()) downloadEunomiaData() +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")) +} +if (!CDMConnector::eunomia_is_available()) { +CDMConnector::downloadEunomiaData(pathToData = Sys.getenv("EUNOMIA_DATA_FOLDER")) +} ``` Let's start by creating two drug cohorts, one for users of diclofenac and another for users of acetaminophen. We'll use the `generateDrugUtilisationCohortSet()` from the DrugUtilisation package so that we can specify a gap era when creating the cohort. From 6a5688bda05c874a5f9f1e744e1340bb8e259970 Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Wed, 27 Dec 2023 20:55:18 +0000 Subject: [PATCH 6/6] optional render --- .../a02_applying_cohort_restrictions.Rmd | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/vignettes/a02_applying_cohort_restrictions.Rmd b/vignettes/a02_applying_cohort_restrictions.Rmd index cd1f91ec..c290347c 100644 --- a/vignettes/a02_applying_cohort_restrictions.Rmd +++ b/vignettes/a02_applying_cohort_restrictions.Rmd @@ -8,11 +8,24 @@ vignette: > --- ```{r, include = FALSE} +library(CDMConnector) +if (Sys.getenv("EUNOMIA_DATA_FOLDER") == "") { +Sys.setenv("EUNOMIA_DATA_FOLDER" = file.path(tempdir(), "eunomia")) +} +if (!dir.exists(file.path(tempdir(), "eunomia"))){ dir.create(file.path(tempdir(), "eunomia")) +} +if (!eunomia_is_available()) { +downloadEunomiaData(pathToData = file.path(tempdir(), "eunomia")) +} + +eunomia_available <- eunomia_is_available() + knitr::opts_chunk$set( collapse = TRUE, message = FALSE, warning = FALSE, - comment = "#>" + comment = "#>", + eval = eunomia_available ) ``` @@ -26,17 +39,6 @@ cdm <- cdm_from_con(con, cdm_schema = "main", write_schema = c(prefix = "my_study_", schema = "main")) ``` -```{r, include = 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")) -} -if (!CDMConnector::eunomia_is_available()) { -CDMConnector::downloadEunomiaData(pathToData = Sys.getenv("EUNOMIA_DATA_FOLDER")) -} -``` - Let's start by creating two drug cohorts, one for users of diclofenac and another for users of acetaminophen. We'll use the `generateDrugUtilisationCohortSet()` from the DrugUtilisation package so that we can specify a gap era when creating the cohort. ```{r} cdm <- generateDrugUtilisationCohortSet(cdm = cdm,