Skip to content

Commit

Permalink
Merge branch 'dev/aki-df' into dev/anemia
Browse files Browse the repository at this point in the history
  • Loading branch information
lymt committed Oct 19, 2020
2 parents 7cd318c + 5277fad commit c96535c
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 5 deletions.
3 changes: 2 additions & 1 deletion DESCRIPTION
Expand Up @@ -30,7 +30,8 @@ Imports:
ellipsis,
rlang,
units,
lubridate
lubridate,
magrittr
Suggests:
testthat,
covr
Expand Down
3 changes: 3 additions & 0 deletions NAMESPACE
Expand Up @@ -4,4 +4,7 @@ S3method(aki,default)
S3method(aki,numeric)
S3method(aki,ts)
S3method(aki,units)
export("%>%")
export(aki)
importFrom(magrittr,"%>%")
importFrom(rlang,.data)
42 changes: 42 additions & 0 deletions R/aki.R
Expand Up @@ -6,6 +6,47 @@
}
}

#' @importFrom rlang .data
#' @importFrom magrittr %>%
.generate_cr_ch <- function(data,
SCr, dttm, pt_id)
{
cr_ts = data %>%
dplyr::ungroup() %>%
{if (TRUE) dplyr::group_by(.data, dplyr::across(dplyr::all_of(pt_id))) else .data} %>%
dplyr::select(dplyr::all_of(c(pt_id, dttm, SCr))) %>%
unique(.data) # To remove any duplicate DTTM entries

# if (nrow(cr_ts) < 2) {
# return(data.frame(
# DateTime_Pathology_Result = as_datetime(NA_real_),
# del_t_ch = as.duration(NA_real_),
# del_t_aki = as.duration(NA_real_),
# del_cr = NA_real_,
# cr = NA_real_
# ))
# }
# Consider filtering out ones post AKI here?

# combns <- combn(nrow(cr_ts), 2)
# Ti_1 = cr_ts[combns[1,],]
# Ti = cr_ts[combns[2,],]
#
# if(AKI_ICU == 0 | is.na(AKI_ICU)) {
# del_t_aki = rep(as.duration(NA_real_), nrow(Ti))
# } else {
# del_t_aki = as.duration(DateTime_AKI_Dx - Ti$Pathology_Result_DTTM)
# }
#
# return(data.frame(
# DateTime_Pathology_Result = Ti$Pathology_Result_DTTM,
# del_t_ch = as.duration(Ti$Pathology_Result_DTTM - Ti_1$Pathology_Result_DTTM),
# del_t_aki = del_t_aki,
# del_cr = Ti$Creatinine_level - Ti_1$Creatinine_level,
# cr = Ti$Creatinine_level
# ))
}

#' Codify AKI from Serum Creatinine and/or Urine Output
#'
#' Using KDIGO Clinical Practice Guideline for Acute Kidney Injury
Expand Down Expand Up @@ -80,5 +121,6 @@ aki.ts <- function(SCr, UO, units = "umol/l", ...) {
#' @rdname aki
#' @export
aki.default <- function(data, SCr, bCr, units = list("SCr" = "umol/l"), na.rm = FALSE, ...) {
predictor <- rlang::as_name(rlang::enquo(SCr))
factor(data, levels = .aki_stages)
}
11 changes: 11 additions & 0 deletions R/utils-pipe.R
@@ -0,0 +1,11 @@
#' Pipe operator
#'
#' See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details.
#'
#' @name %>%
#' @rdname pipe
#' @keywords internal
#' @export
#' @importFrom magrittr %>%
#' @usage lhs \%>\% rhs
NULL
12 changes: 12 additions & 0 deletions man/pipe.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions tests/testthat/test-aki.R
Expand Up @@ -71,8 +71,8 @@ test_that("aki() for vector of SCr in mg/dl with baseline", {
})

data <- data.frame(
pt_id = c(rep("pt1", 11), rep("pt2", 13)),
dttm = c(
pt_id_ = c(rep("pt1", 11), rep("pt2", 13)),
dttm_ = c(
seq(
lubridate::as_datetime("2020-10-18 09:00:00", tz = "Australia/Melbourne"),
lubridate::as_datetime("2020-10-20 09:00:00", tz = "Australia/Melbourne"),
Expand All @@ -84,11 +84,11 @@ data <- data.frame(
length.out = 13
)
),
SCr = c(
SCr_ = c(
units::set_units(seq(2.0, 4.5, by = 0.25), "mg/dl"),
units::set_units(seq(3.0, 4.2, by = 0.10), "mg/dl")
),
bCr = c(
bCr_ = c(
rep(units::set_units(1.8, "mg/dl"), 11),
rep(units::set_units(3.0, "mg/dl"), 13)
)
Expand Down

0 comments on commit c96535c

Please sign in to comment.