From cebac37a4f8983a520244f0637558fb06869d9c4 Mon Sep 17 00:00:00 2001 From: edward-burn <9583964+edward-burn@users.noreply.github.com> Date: Wed, 30 Oct 2024 17:12:27 +0000 Subject: [PATCH] support null in matchedDiagnostics closes #94 --- R/matchedDiagnostics.R | 5 +++-- tests/testthat/test-matchedDiagnostics.R | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/R/matchedDiagnostics.R b/R/matchedDiagnostics.R index bbe7275..48e79d1 100644 --- a/R/matchedDiagnostics.R +++ b/R/matchedDiagnostics.R @@ -54,7 +54,7 @@ matchedDiagnostics <- function(cohort, matchedSample = 1000){ - omopgenerics::assertNumeric(matchedSample, min = 1) + omopgenerics::assertNumeric(matchedSample, min = 1, null = TRUE) cdm <- omopgenerics::cdmReference(cohort) cohortName <- omopgenerics::tableName(cohort) @@ -72,7 +72,8 @@ matchedDiagnostics <- function(cohort, n = matchedSample, name = matchedCohortTable) } else { - cdm[[matchedCohortTable]] <- cdm[[cohortName]] + cdm[[matchedCohortTable]] <- cdm[[cohortName]] |> + dplyr::compute(name = matchedCohortTable, temporary = FALSE) } cli::cli_bullets(c("*" = "{.strong Generating a age and sex matched cohorts}")) diff --git a/tests/testthat/test-matchedDiagnostics.R b/tests/testthat/test-matchedDiagnostics.R index f731961..42d08d7 100644 --- a/tests/testthat/test-matchedDiagnostics.R +++ b/tests/testthat/test-matchedDiagnostics.R @@ -28,6 +28,9 @@ test_that("cohort to pop diagnostics", { schema ="main", overwrite = TRUE) expect_no_error(result <- cdm$my_cohort |> matchedDiagnostics()) + # can be NULL and would do no sampling + cdm$my_cohort |> + matchedDiagnostics(matchedSample = NULL) # expected errors expect_error(matchedDiagnostics(cohort = "not a cohort"))