diff --git a/R/mockCohort.R b/R/mockCohort.R index 355d8b0..0097054 100644 --- a/R/mockCohort.R +++ b/R/mockCohort.R @@ -89,6 +89,7 @@ mockCohort <- function(cdm, rows_to_keep <- sum(numberRows / 1.2) + # generate cohort table cohort <- list() if (length(numberRows) == 1) { @@ -193,12 +194,15 @@ addCohortDates <- dplyr::mutate(dplyr::across( dplyr::all_of(cols), ~ .x / .data$cum_sum)) |> dplyr::select(-"cum_sum") + + if(nrow(observationPeriod)>0){ observationPeriod <- observationPeriod |> dplyr::mutate(rand = stats::runif(dplyr::n())) |> dplyr::group_by(.data$person_id) |> dplyr::filter(.data$rand == min(.data$rand)) |> dplyr::ungroup() |> dplyr::select(-"rand") + } x <- x |> dplyr::inner_join( observationPeriod |> diff --git a/tests/testthat/test-mockCohort.R b/tests/testthat/test-mockCohort.R index ed3fda5..16d5cb8 100644 --- a/tests/testthat/test-mockCohort.R +++ b/tests/testthat/test-mockCohort.R @@ -28,4 +28,10 @@ test_that("mock cohort simple test", { numberCohorts = 2, cohortName = c("omock_cohort_1", "omock_cohort_2") )) + + expect_no_warning(omock::mockPerson(nPerson = 10) |> + omock::mockCohort(name = "cohort")) + + + })