Skip to content

Commit

Permalink
Merge pull request #102 from OHDSI/fixes_warning_from_mockPerson_mock…
Browse files Browse the repository at this point in the history
…_cohort

fixes
  • Loading branch information
ilovemane committed Aug 8, 2024
2 parents a93b2d9 + f7ed1d0 commit 79d248d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/mockCohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ mockCohort <- function(cdm,
rows_to_keep <- sum(numberRows / 1.2)



# generate cohort table
cohort <- list()
if (length(numberRows) == 1) {
Expand Down Expand Up @@ -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 |>
Expand Down
6 changes: 6 additions & 0 deletions tests/testthat/test-mockCohort.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))



})

0 comments on commit 79d248d

Please sign in to comment.