Skip to content

Commit

Permalink
Made S3 generic/method consistent
Browse files Browse the repository at this point in the history
  • Loading branch information
lymt committed Oct 12, 2020
1 parent 59991ee commit 642689f
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 20 deletions.
1 change: 1 addition & 0 deletions .Rbuildignore
Expand Up @@ -14,3 +14,4 @@
^\.png$
^README_cache/
^codecov\.yml$
^resources$
6 changes: 4 additions & 2 deletions DESCRIPTION
Expand Up @@ -21,12 +21,14 @@ License: MIT + file LICENSE
URL: https://github.com/alwinw/epocakir
BugReports: https://github.com/alwinw/epocakir/issues
Depends:
R
R (>= 3.5.0)
Imports:
dplyr,
tidyselect,
tibble,
forcats
forcats,
ellipsis,
rlang
Suggests:
testthat,
covr
Expand Down
41 changes: 31 additions & 10 deletions R/aki.R
@@ -1,24 +1,46 @@
#' Codify AKI from Serum Creatinine and/or Urine Output
#'
#' Some additional details
#' Using KDIGO Clinical Practice Guideline for Acute Kidney Injury
#' Volume 2 | Issue 1 | March 2012
#'
#' @param x numeric number
#' Provided a series of Serum Creatinine readings and/or Urine Output, aki()
#' calculates whether or not a patient has AKI. The staging (1, 2, 3) of AKI is
#' also calculated
#'
#' @return
#' @param data A data.frame with the data needed for serum creatinine (SCr)
#' and/or urine output (UO)
#' @param SCr The variable name, e.g. "cr", to be used for determining
#' AKI based on creatinine level. A numeric vector or time series of
#' serum creatinine values if the data argument is unused
#' @param UO The variable name, e.g. "urine", to be used for determining
#' AKI based on urine output. A numeric vector or time series of
#' urine output values if the data argument is unused
#' @param bCr The variable name, e.g. "baseline_cr", to be used for determining
#' AKI based on urine output. A single numeric value of
#' baseline creatinine if the data argument is unused
#' @param units (character) Units of SCr and UO metric (mg/dl) or SI (umol/l)
#' #TOFIX
#' @param na.rm (logical) If TRUE, missing values are removed
#' @param ... Further optional arguments that will be passed to method.
#'
#' @examples
#' aki(seq(60, 200, by = 20))
#' aki(SCr = seq(60, 200, by = 20), bCr = 50)
#' @export
aki <- function(x, ...) {
UseMethod("aki", x)
aki <- function(...) {
ellipsis::check_dots_used()
UseMethod("aki")
}

.aki_stages <- factor(c("AKI Stage 1", "AKI Stage 2", "AKI Stage 3", "No AKI"))


#' @rdname aki
#' @export
aki.numeric <- function(SCr, bCr = NULL, na.rm = FALSE) {
aki.numeric <- function(SCr, bCr = NULL, units = "umol/l", na.rm = FALSE, ...) {
if (is.null(bCr)) bCr <- min(SCr, na.rm = na.rm)
aki_stages <- dplyr::case_when(
# Need one for SCr > X
SCr >= 3.0 * bCr ~ .aki_stages[3],
SCr >= 2.0 * bCr ~ .aki_stages[2],
SCr >= 1.5 * bCr ~ .aki_stages[1],
Expand All @@ -29,13 +51,12 @@ aki.numeric <- function(SCr, bCr = NULL, na.rm = FALSE) {

#' @rdname aki
#' @export
aki.ts <- function(ts_data) {
aki.ts <- function(SCr, UO, units = "umol/l", ...) {

}


#' @rdname aki
#' @export
aki.default <- function(x) {
factor(x, levels = .aki_stages)
aki.default <- function(data, SCr, bCr, units = list("SCr" = "umol/l"), na.rm = FALSE, ...) {
factor(data, levels = .aki_stages)
}
43 changes: 35 additions & 8 deletions man/aki.Rd

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

0 comments on commit 642689f

Please sign in to comment.