diff --git a/DESCRIPTION b/DESCRIPTION index 2600386..f56bcb8 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -30,7 +30,8 @@ Imports: ellipsis, rlang, units, - lubridate + lubridate, + magrittr Suggests: testthat, covr diff --git a/NAMESPACE b/NAMESPACE index a6f79f9..6226f69 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -4,4 +4,7 @@ S3method(aki,default) S3method(aki,numeric) S3method(aki,ts) S3method(aki,units) +export("%>%") export(aki) +importFrom(magrittr,"%>%") +importFrom(rlang,.data) diff --git a/R/aki.R b/R/aki.R index 10dfb32..905efd8 100644 --- a/R/aki.R +++ b/R/aki.R @@ -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 @@ -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) } diff --git a/R/utils-pipe.R b/R/utils-pipe.R new file mode 100644 index 0000000..e79f3d8 --- /dev/null +++ b/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 diff --git a/man/pipe.Rd b/man/pipe.Rd new file mode 100644 index 0000000..0eec752 --- /dev/null +++ b/man/pipe.Rd @@ -0,0 +1,12 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/utils-pipe.R +\name{\%>\%} +\alias{\%>\%} +\title{Pipe operator} +\usage{ +lhs \%>\% rhs +} +\description{ +See \code{magrittr::\link[magrittr:pipe]{\%>\%}} for details. +} +\keyword{internal} diff --git a/tests/testthat/test-aki.R b/tests/testthat/test-aki.R index 48d4171..6fc8184 100644 --- a/tests/testthat/test-aki.R +++ b/tests/testthat/test-aki.R @@ -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"), @@ -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) )