diff --git a/R/callback-cncpt.R b/R/callback-cncpt.R index cd919e0f..c4692c30 100644 --- a/R/callback-cncpt.R +++ b/R/callback-cncpt.R @@ -4,37 +4,11 @@ collect_dots <- function(concepts, interval, ..., merge_dat = FALSE) { dots <- list(...) - if (length(concepts) == 1L) { - - assert_that(identical(length(dots), 1L)) - - res <- dots[[1L]] - - if (is_ts_tbl(res)) { - ival <- coalesce(interval, interval(res)) - assert_that(has_interval(res, ival)) - } else { - assert_that(is_df(res)) - } - - return(res) - } - - if (length(dots) == 1L) { - dots <- dots[[1L]] - } - - if (is.null(names(dots))) { - names(dots) <- concepts - } - if (not_null(names(concepts))) { concepts <- chr_ply(concepts, grep, names(dots), value = TRUE, use_names = TRUE) } - assert_that(setequal(names(dots), concepts)) - res <- dots[concepts] assert_that(all_map(has_col, res, concepts)) @@ -45,7 +19,9 @@ collect_dots <- function(concepts, interval, ..., merge_dat = FALSE) { ival <- check_interval(res, interval) - if (merge_dat) { + if (length(res) == 1) { + res <- res[[1]] + } else if (merge_dat) { res <- reduce(merge, res, all = TRUE) } else { attr(res, "ival_checked") <- ival diff --git a/R/concept-load.R b/R/concept-load.R index 6774a5dd..1df90c5c 100644 --- a/R/concept-load.R +++ b/R/concept-load.R @@ -547,7 +547,7 @@ load_concepts.rec_cncpt <- function(x, aggregate = NULL, patient_ids = NULL, ext <- list(patient_ids = patient_ids, id_type = id_type, interval = coalesce(x[["interval"]], interval), - progress = progress) + ..., progress = progress) sub <- x[["items"]] agg <- x[["aggregate"]] @@ -606,8 +606,6 @@ load_concepts.item <- function(x, patient_ids = NULL, id_type = "icustay", load_concepts.itm <- function(x, patient_ids = NULL, id_type = "icustay", interval = hours(1L), ...) { - warn_dots(..., ok_args = "keep_components") - res <- do_itm_load(x, id_type, interval = interval) res <- merge_patid(res, patient_ids) res <- do_callback(x, res) diff --git a/R/data-load.R b/R/data-load.R index 53187a3c..52f04c5d 100644 --- a/R/data-load.R +++ b/R/data-load.R @@ -119,8 +119,8 @@ load_difftime.mimic_tbl <- function(x, rows, cols = colnames(x), time_vars = ricu::time_vars(x), ...) { warn_dots(...) - - load_mihi(x, {{ rows }}, cols, id_hint, time_vars) + dt_round_min <- function(x, y) round_to(difftime(x, y, units = "mins")) + do_load_difftime(x, {{ rows }}, cols, id_hint, time_vars, dt_round_min) } #' @rdname load_src @@ -130,8 +130,8 @@ load_difftime.eicu_tbl <- function(x, rows, cols = colnames(x), time_vars = ricu::time_vars(x), ...) { warn_dots(...) - - load_eiau(x, {{ rows }}, cols, id_hint, time_vars, min_as_mins) + dt_round_min <- function(x, y) min_as_mins(x) + do_load_difftime(x, {{ rows }}, cols, id_hint, time_vars, dt_round_min) } #' @rdname load_src @@ -141,8 +141,8 @@ load_difftime.hirid_tbl <- function(x, rows, cols = colnames(x), time_vars = ricu::time_vars(x), ...) { warn_dots(...) - - load_mihi(x, {{ rows }}, cols, id_hint, time_vars) + dt_round_min <- function(x, y) round_to(difftime(x, y, units = "mins")) + do_load_difftime(x, {{ rows }}, cols, id_hint, time_vars, dt_round_min) } #' @rdname load_src @@ -152,8 +152,8 @@ load_difftime.aumc_tbl <- function(x, rows, cols = colnames(x), time_vars = ricu::time_vars(x), ...) { warn_dots(...) - - load_eiau(x, {{ rows }}, cols, id_hint, time_vars, ms_as_mins) + dt_round_min <- function(x, y) round_to(ms_as_mins(x - y)) + do_load_difftime(x, {{ rows }}, cols, id_hint, time_vars, dt_round_min) } #' @rdname load_src @@ -163,8 +163,8 @@ load_difftime.miiv_tbl <- function(x, rows, cols = colnames(x), time_vars = ricu::time_vars(x), ...) { warn_dots(...) - - load_mihi(x, {{ rows }}, cols, id_hint, time_vars) + dt_round_min <- function(x, y) round_to(difftime(x, y, units = "mins")) + do_load_difftime(x, {{ rows }}, cols, id_hint, time_vars, dt_round_min) } #' @rdname load_src @@ -195,56 +195,32 @@ resolve_id_hint <- function(tbl, hint) { id_vars(opts[hits]) } -load_mihi <- function(x, rows, cols, id_hint, time_vars) { - - dt_round_min <- function(x, y) round_to(difftime(x, y, units = "mins")) - +do_load_difftime <- function(x, rows, cols, id_hint, time_vars, time_fn) { + id_col <- resolve_id_hint(x, id_hint) - + assert_that(is.string(id_col), id_col %in% colnames(x)) - + if (!id_col %in% cols) { cols <- c(cols, id_col) } - + time_vars <- intersect(time_vars, cols) - + dat <- load_src(x, {{ rows }}, cols) - + if (length(time_vars)) { - + dat <- merge(dat, id_origin(x, id_col, origin_name = "origin"), by = id_col) - + dat <- dat[, - c(time_vars) := lapply(.SD, dt_round_min, get("origin")), - .SDcols = time_vars + c(time_vars) := lapply(.SD, time_fn, get("origin")), + .SDcols = time_vars ] dat <- dat[, c("origin") := NULL] } - - as_id_tbl(dat, id_vars = id_col, by_ref = TRUE) -} - -load_eiau <- function(x, rows, cols, id_hint, time_vars, mins_fun) { - - id_col <- resolve_id_hint(x, id_hint) - - if (!id_col %in% cols) { - cols <- c(id_col, cols) - } - - time_vars <- intersect(time_vars, cols) - - dat <- load_src(x, {{ rows }}, cols) - - if (length(time_vars)) { - - assert_that(has_col(dat, id_col)) - - dat <- dat[, c(time_vars) := lapply(.SD, mins_fun), .SDcols = time_vars] - } - + as_id_tbl(dat, id_vars = id_col, by_ref = TRUE) } diff --git a/inst/extdata/config/concept-dict.R b/inst/extdata/config/concept-dict.R index 0b79cb25..dee3d465 100644 --- a/inst/extdata/config/concept-dict.R +++ b/inst/extdata/config/concept-dict.R @@ -2769,7 +2769,6 @@ cfg <- list( omopid = 132797L, category = "outcome", callback = "sep3", - keep_components = c(FALSE, TRUE), class = "rec_cncpt" ), bnd = list( diff --git a/inst/extdata/config/concept-dict.json b/inst/extdata/config/concept-dict.json index 10fd7f3c..d80e1880 100644 --- a/inst/extdata/config/concept-dict.json +++ b/inst/extdata/config/concept-dict.json @@ -5254,7 +5254,6 @@ "omopid": 132797, "category": "outcome", "callback": "sep3", - "keep_components": [false, true], "class": "rec_cncpt" }, "sex": { diff --git a/tests/testthat/test-callback.R b/tests/testthat/test-callback.R index 0d151157..51fd5db2 100644 --- a/tests/testthat/test-callback.R +++ b/tests/testthat/test-callback.R @@ -272,5 +272,5 @@ test_that("susp_inf", { 57, 61, 70)), susp_inf = rep(TRUE, 6L), interval = hours(1L) ) - expect_identical(susp_inf(abx, samp), expected) + expect_identical(susp_inf(abx = abx, samp = samp), expected) }) diff --git a/tests/testthat/test-scores.R b/tests/testthat/test-scores.R index 169c43c4..6d1d316f 100644 --- a/tests/testthat/test-scores.R +++ b/tests/testthat/test-scores.R @@ -42,7 +42,7 @@ test_that("suspicion of infection", { expect_equal(interval(si_ei), hours(1L)) }) -sep3 <- sep3(so_mi, si_mi) +sep3 <- sep3(sofa = so_mi, susp_inf = si_mi) test_that("sepsis 3", {