Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when trying to upgrade_id during load_win #22

Open
prockenschaub opened this issue Nov 7, 2022 · 2 comments
Open

Error when trying to upgrade_id during load_win #22

prockenschaub opened this issue Nov 7, 2022 · 2 comments
Labels
bug Something isn't working

Comments

@prockenschaub
Copy link
Collaborator

Problem

When trying to load an itm, it may be necessary to upgrade the ids, e.g., when loading prescriptions (hadm) in miiv with id_type='icustay'. This leads to an error if the target is a win_tbl

az_wi <- new_itm(
   src = "miiv", 
   table = "prescriptions", 
   sub_var = "drug", 
   regex = "aztreonam", 
   dur_var = "stoptime", 
   class = "rgx_itm", 
   target = "win_tbl")
res <- do_itm_load(az_wi)
#> Error in colnamesInt(x, names(on), check_dups = FALSE) :
#>  argument specifying columns specify non existing column(s): cols[3]='stoptime'

This error originates in the following lines because stoptime is part of meta_vars(x)

ricu/R/data-utils.R

Lines 681 to 684 in 09902bd

map <- id_map(src, id_vars(x), target_id, sft, idx)
res <- map[x, on = meta_vars(x), roll = -Inf, rollends = TRUE]
res <- res[, c(cols) := lapply(.SD, `-`, get(sft)), .SDcols = cols]

but stoptime was removed previously in

ricu/R/data-load.R

Lines 440 to 442 in 09902bd

time_vars <- setdiff(intersect(time_vars, colnames(res)), dur_var)
res <- change_id(res, id_var, x, cols = time_vars, keep_old_id = FALSE)

Expected behaviour

No error with the following result

az_ts <- new_itm(
   src = "miiv", 
   table = "prescriptions", 
   sub_var = "drug", 
   regex = "aztreonam", 
   dur_var = "stoptime", 
   class = "rgx_itm", 
   target = 'ts_tbl')
res <- do_itm_load(az_ts)
res[, "stoptime" := get("stoptime") - get("starttime")]
as_win_tbl(res, dur_var="stoptime")
#> # A `win_tbl`:  1,363 ✖ 5
#> # Id var:       `stay_id`
#> # Index var:    `starttime` (1 hours)
#> # Duration var: `stoptime`
#>        stay_id starttime stoptime  drug      dose_val_rx
#>          <int> <drtn>    <drtn>    <chr>     <chr>
#>     1 30025040   1 hours  34 hours Aztreonam 1000
#> ...

Solution

Add a dedicated function upgrade_id.win_tbl.

@prockenschaub
Copy link
Collaborator Author

As an add-on: load_win currently does not apply change_interval to dur_var, since its removed from time_vars earlier.

@dplecko
Copy link
Member

dplecko commented Dec 29, 2023

This one is for @nbenn, perhaps he can make some comments or help with this issue.

@dplecko dplecko closed this as completed Dec 29, 2023
@dplecko dplecko reopened this Dec 29, 2023
@prockenschaub prockenschaub added the bug Something isn't working label Apr 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants