-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from dylanrussellmd/dindo
Merge Dindo into master
- Loading branch information
Showing
11 changed files
with
250 additions
and
47 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,40 @@ | ||
Package: nsqipr | ||
Title: Interact with NSQIP data via R | ||
Version: 0.0.0.9000 | ||
Authors@R: | ||
person(given = "Dylan", | ||
family = "Russell", | ||
role = c("aut", "cre"), | ||
email = "[email protected]", | ||
comment = c(ORCID = "0000-0002-9543-9897")) | ||
Description: Streamlines reading and writing clean NSQIP data. | ||
License: CC0 | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.1.0 | ||
Suggests: | ||
knitr, | ||
rmarkdown, | ||
testthat, | ||
spelling | ||
VignetteBuilder: knitr | ||
URL: https://github.com/dylanrussellmd/nsqipr | ||
BugReports: https://github.com/dylanrussellmd/nsqipr/issues | ||
Language: en-US | ||
Imports: | ||
stringr, | ||
readr, | ||
magrittr, | ||
usethis, | ||
dplyr, | ||
tibble, | ||
lubridate, | ||
purrr, | ||
tools, | ||
utils, | ||
filesstrings, | ||
progress | ||
Depends: | ||
R (>= 3.5.0) | ||
Package: nsqipr | ||
Title: Interact with NSQIP data via R | ||
Version: 0.0.0.9000 | ||
Authors@R: | ||
person(given = "Dylan", | ||
family = "Russell", | ||
role = c("aut", "cre"), | ||
email = "[email protected]", | ||
comment = c(ORCID = "0000-0002-9543-9897")) | ||
Description: Streamlines reading and writing clean NSQIP data. | ||
License: CC0 | ||
Encoding: UTF-8 | ||
LazyData: true | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.1.1 | ||
Suggests: | ||
knitr, | ||
rmarkdown, | ||
testthat, | ||
spelling | ||
VignetteBuilder: knitr | ||
URL: https://github.com/dylanrussellmd/nsqipr | ||
BugReports: https://github.com/dylanrussellmd/nsqipr/issues | ||
Language: en-US | ||
Imports: | ||
stringr, | ||
readr, | ||
magrittr, | ||
usethis, | ||
dplyr, | ||
tibble, | ||
lubridate, | ||
purrr, | ||
tools, | ||
utils, | ||
filesstrings, | ||
progress, | ||
furniture | ||
Depends: | ||
R (>= 3.5.0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
#' Check if a boolean is TRUE and not NA | ||
#' | ||
#' This represent a key assumption about the Dindo classification sorting. If a complication is missing (NA), it is considered FALSE | ||
#' for the purposes of the Dindo classification. | ||
#' | ||
#' @param bool a logical vector | ||
#' | ||
#' @return a logical vector | ||
#' | ||
#' @keywords internal | ||
#' | ||
checkTrue <- function(bool) { | ||
(bool %in% TRUE) & !is.na(bool) | ||
} | ||
|
||
#' Check if any trues exist row-wise in a logical matrix. | ||
#' | ||
#' @param ... a list of logical vectors or a data frame | ||
#' | ||
#' @return a logical vector. TRUE if any trues, FALSE if no trues. | ||
#' | ||
#' @keywords internal | ||
#' | ||
checkAnyTrue <- function(...) { | ||
apply(cbind(...), 2, checkTrue) %>% | ||
apply(., 1, any) | ||
} | ||
|
||
#' Check if a patient has died within 30 days of the index procedure. Assumes that if a patient died, a date would be | ||
#' recorded in `yrdeath`. | ||
#' | ||
#' @param col a vector of any type | ||
#' | ||
#' @return a logical vector. TRUE if not NA, FALSE if NA. | ||
#' | ||
#' @keywords internal | ||
#' | ||
isDead <- function(col) { | ||
!is.na(col) | ||
} | ||
|
||
#' Check if any trues exist row-wise in a logical matrix. | ||
#' | ||
#' @param ... a list of vectors of any type or a data frame | ||
#' | ||
#' @return a logical vector. TRUE if any NA values in row, FALSE if no NA values in row. | ||
#' | ||
#' @keywords internal | ||
#' | ||
checkAnyDead <- function(...) { | ||
apply(cbind(...), 2, isDead) %>% | ||
apply(., 1, any) | ||
} | ||
|
||
|
||
#' Classifies a patient according to the Dindo-Clavien surgical complication grading scale. | ||
#' | ||
#' @param df a dataframe including relevant columns containing information on specific post-operative complications. | ||
#' | ||
#' @return a numeric vector representing the Dindo-Clavien classification. | ||
#' | ||
#' @export | ||
#' | ||
dindo <- function(df) { | ||
e <- new.env() | ||
dindo_list <- list(dindo_1, dindo_2, dindo_3, dindo_4, dindo_5) | ||
dindo <- rep(0, nrow(df)) | ||
|
||
dindo_cat <- function(x, y, df) { | ||
dindo_cols <- colnames(df)[which(colnames(df) %in% x)] | ||
if(length(dindo_cols) > 0) { | ||
if(y == 5) { | ||
dindo[which(checkAnyDead(df[dindo_cols]))] <<- y | ||
} else { | ||
dindo[which(checkAnyTrue(df[dindo_cols]))] <<- y | ||
} | ||
} | ||
} | ||
|
||
purrr::imap(dindo_list, ~dindo_cat(.x, .y, df)) | ||
return(dindo) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
testthat::test_that("checkTrue assigns TRUE correctly", { | ||
testthat::expect_true(checkTrue(TRUE)) | ||
testthat::expect_false(checkTrue(NA)) | ||
testthat::expect_false(checkTrue(FALSE)) | ||
}) | ||
|
||
testthat::test_that("checkAnyTrue assigns TRUE correctly", { | ||
testthat::expect_equal(checkAnyTrue(c(TRUE, FALSE, TRUE, FALSE), c(FALSE, FALSE, NA, NA )), c(TRUE, FALSE, TRUE, FALSE)) | ||
}) | ||
|
||
testthat::test_that("checkTrue and checkAnyTrue are equal if given a single vector", { | ||
testthat::expect_equal(checkTrue(c(TRUE, TRUE, TRUE, FALSE)), checkAnyTrue(c(TRUE, TRUE, TRUE, FALSE))) | ||
}) | ||
|
||
testthat::test_that("isDead assigns TRUE correctly", { | ||
testthat::expect_true(isDead("dead")) | ||
testthat::expect_false(isDead(NA)) | ||
}) | ||
|
||
testthat::test_that("checkAnyDead assigns TRUE correctly", { | ||
testthat::expect_equal(checkAnyDead(c("dead", NA, NA), c(NA, "dead", NA)), c(TRUE, TRUE, FALSE)) | ||
}) |