Skip to content

Commit

Permalink
Fix timediff for AUMCdb
Browse files Browse the repository at this point in the history
  • Loading branch information
prockenschaub committed Mar 15, 2024
1 parent 7f2cc42 commit fae9603
Showing 1 changed file with 33 additions and 4 deletions.
37 changes: 33 additions & 4 deletions R/data-load.R
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ load_difftime.eicu_tbl <- function(x, rows, cols = colnames(x),

warn_dots(...)

load_eiau(x, {{ rows }}, cols, id_hint, time_vars, min_as_mins)
load_eisi(x, {{ rows }}, cols, id_hint, time_vars, min_as_mins)
}

#' @rdname load_src
Expand All @@ -153,7 +153,7 @@ load_difftime.aumc_tbl <- function(x, rows, cols = colnames(x),

warn_dots(...)

load_eiau(x, {{ rows }}, cols, id_hint, time_vars, ms_as_mins)
load_au(x, {{ rows }}, cols, id_hint, time_vars)

Check warning on line 156 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L156

Added line #L156 was not covered by tests
}

#' @rdname load_src
Expand All @@ -175,7 +175,7 @@ load_difftime.sic_tbl <- function(x, rows, cols = colnames(x),

sec_as_mins <- function(x) min_as_mins(as.integer(x / 60))
warn_dots(...)
load_eiau(x, {{ rows }}, cols, id_hint, time_vars, sec_as_mins)
load_eisi(x, {{ rows }}, cols, id_hint, time_vars, sec_as_mins)

Check warning on line 178 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L178

Added line #L178 was not covered by tests
}

#' @rdname load_src
Expand Down Expand Up @@ -237,7 +237,7 @@ load_mihi <- function(x, rows, cols, id_hint, time_vars) {
as_id_tbl(dat, id_vars = id_col, by_ref = TRUE)
}

load_eiau <- function(x, rows, cols, id_hint, time_vars, mins_fun) {
load_eisi <- function(x, rows, cols, id_hint, time_vars, mins_fun) {

id_col <- resolve_id_hint(x, id_hint)

Expand All @@ -259,6 +259,35 @@ load_eiau <- function(x, rows, cols, id_hint, time_vars, mins_fun) {
as_id_tbl(dat, id_vars = id_col, by_ref = TRUE)
}

load_au <- function(x, rows, cols, id_hint, time_vars) {
dt_round_min <- function(x, y) round_to(ms_as_mins(x - y))

Check warning on line 263 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L263

Added line #L263 was not covered by tests

id_col <- resolve_id_hint(x, id_hint)

Check warning on line 265 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L265

Added line #L265 was not covered by tests

assert_that(is.string(id_col), id_col %in% colnames(x))

Check warning on line 267 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L267

Added line #L267 was not covered by tests

if (!id_col %in% cols) {
cols <- c(cols, id_col)

Check warning on line 270 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L269-L270

Added lines #L269 - L270 were not covered by tests
}

time_vars <- intersect(time_vars, cols)

Check warning on line 273 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L273

Added line #L273 was not covered by tests

dat <- load_src(x, {{ rows }}, cols)

Check warning on line 275 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L275

Added line #L275 was not covered by tests

if (length(time_vars)) {

Check warning on line 277 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L277

Added line #L277 was not covered by tests

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

Check warning on line 283 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L279-L283

Added lines #L279 - L283 were not covered by tests
]
dat <- dat[, c("origin") := NULL]

Check warning on line 285 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L285

Added line #L285 was not covered by tests
}

as_id_tbl(dat, id_vars = id_col, by_ref = TRUE)

Check warning on line 288 in R/data-load.R

View check run for this annotation

Codecov / codecov/patch

R/data-load.R#L288

Added line #L288 was not covered by tests
}

#' Load data as `id_tbl` or `ts_tbl` objects
#'
#' Building on functionality provided by [load_src()] and [load_difftime()],
Expand Down

0 comments on commit fae9603

Please sign in to comment.