diff --git a/R/first_isolate.R b/R/first_isolate.R index 4ef2c7bb..9aa36aee 100755 --- a/R/first_isolate.R +++ b/R/first_isolate.R @@ -172,8 +172,8 @@ first_isolate <- function(tbl, if (is.null(col_date)) { stop("`col_date` must be set.", call. = FALSE) } - # convert to Date - tbl[, col_date] <- as.Date(tbl[, col_date]) + # convert to Date (pipes for supporting tibbles too) + tbl[, col_date] <- tbl %>% pull(col_date) %>% as.Date() # -- patient id if (is.null(col_patient_id) & any(colnames(tbl) %like% "^(patient|patid)")) { diff --git a/tests/testthat/test-first_isolate.R b/tests/testthat/test-first_isolate.R index b9ed1838..db550b80 100755 --- a/tests/testthat/test-first_isolate.R +++ b/tests/testthat/test-first_isolate.R @@ -26,6 +26,20 @@ test_that("first isolates work", { info = TRUE), na.rm = TRUE)), 1411) + # should be same for tibbles + expect_equal( + suppressWarnings( + sum( + first_isolate(tbl = septic_patients %>% dplyr::as_tibble() %>% mutate(keyab = key_antibiotics(.)), + # let syntax determine these automatically: + # col_date = "date", + # col_patient_id = "patient_id", + # col_mo = "mo", + # col_keyantibiotics = "keyab", + type = "keyantibiotics", + info = TRUE), + na.rm = TRUE)), + 1411) # and 1435 when not ignoring I expect_equal( suppressWarnings(