From 6c1e15ff1aa22e7c484abd0b7923aa9056e21ad5 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Tue, 25 Aug 2020 22:21:08 -1000 Subject: [PATCH 1/3] dindo pretty much functional! --- R/col_definitions.R | 12 +++++- R/conv_acs.R | 3 +- R/dindo.R | 81 +++++++++++++++++++++++++++++++++++++ R/nsqip.R | 2 +- tests/testthat/test-dindo.R | 22 ++++++++++ 5 files changed, 117 insertions(+), 3 deletions(-) create mode 100644 R/dindo.R create mode 100644 tests/testthat/test-dindo.R diff --git a/R/col_definitions.R b/R/col_definitions.R index 0205354..561036a 100644 --- a/R/col_definitions.R +++ b/R/col_definitions.R @@ -14,7 +14,17 @@ reason_cols <- c("readmsuspreason1", "readmunrelsusp1", "readmsuspreason2", "rea redundant_cols <- c("race_new","readmission","unplanreadmission","reoperation", "aaa_andiam_unk", "col_steroid_unk","col_oral_antibiotic_unk","col_chemo_unk","col_margins_unk","col_ileus_unk","col_mech_bowel_prep_unk") -acs_cols <- c("caseid","pufyear","sex","race","race_new","ethnicity_hispanic","prncptx","cpt","workrvu","inout","transt","age","admyr","admsyr","operyr","electsurg","dischdest","anesthes","anesthes_other","attend","surgspec","height","weight","diabetes","insulin","smoke","packs","etoh","dyspnea","when_dyspnea","dnr","fnstatus1","fnstatus2","ventilat","hxcopd","cpneumon","ascites","esovar","hxchf","hxmi","prvpci","prvpcs","hxangina","hypermed","hxpvd","restpain","renafail","dialysis","impsens","coma","hemi","hxtia","cva","cvano","tumorcns","para","quad","discancr","wndinf","steroid","wtloss","bleeddis","transfus","chemo","radio","prsepis","type_prsepis","pregnancy","proper30","dprna","dprbun","dprcreat","dpralbum","dprbili","dprsgot","dpralkph","dprwbc","dprhct","dprplate","dprptt","dprpt","dprinr","prsodm","prbun","prcreat","pralbum","prbili","prsgot","pralkph","prwbc","prhct","prplate","prptt","prinr","prpt","otherproc1","othercpt1","otherwrvu1","otherproc2","othercpt2","otherwrvu2","otherproc3","othercpt3","otherwrvu3","otherproc4","othercpt4","otherwrvu4","otherproc5","othercpt5","otherwrvu5","otherproc6","othercpt6","otherwrvu6","otherproc7","othercpt7","otherwrvu7","otherproc8","othercpt8","otherwrvu8","otherproc9","othercpt9","otherwrvu9","otherproc10","othercpt10","otherwrvu10","concurr1","concpt1","conwrvu1","concurr2","concpt2","conwrvu2","concurr3","concpt3","conwrvu3","concurr4","concpt4","conwrvu4","concurr5","concpt5","conwrvu5","concurr6","concpt6","conwrvu6","concurr7","concpt7","conwrvu7","concurr8","concpt8","conwrvu8","concurr9","concpt9","conwrvu9","concurr10","concpt10","conwrvu10","opnote","pgy","emergncy","wndclas","asaclas","airtra","mallamp","rbc","anesurg","surgane","dpatrm","anetime","optime","typeintoc","sdisdt","hdisdt","yrdeath","tothlos","admqtr","htooday","stooday","totslos","nsupinfec","supinfec","dsupinfec","sssipatos","nwndinfd","wndinfd","dwndinfd","dssipatos","norgspcssi","orgspcssi","dorgspcssi","ossipatos","ndehis","dehis","ddehis","noupneumo","oupneumo","doupneumo","pnapatos","nreintub","reintub","dreintub","npulembol","pulembol","dpulembol","nfailwean","failwean","dfailwean","ventpatos","nrenainsf","renainsf","drenainsf","noprenafl","oprenafl","doprenafl","nurninfec","urninfec","durninfec","utipatos","ncnscva","cnscva","dcnscva","ncnscoma","cnscoma","dcnscoma","nneurodef","neurodef","dneurodef","ncdarrest","cdarrest","dcdarrest","ncdmi","cdmi","dcdmi","nothbleed","othbleed","dothbleed","nothgrafl","othgrafl","dothgrafl","nothdvt","othdvt","dothdvt","nothsysep","othsysep","dothsysep","sepsispatos","nothseshock","othseshock","dothseshock","sepshockpatos","othcdiff","nothcdiff","dothcdiff","podiag","podiagtx","returnor","dsdtohd","dopertod","doptodis","mortprob","morbprob","stillinhosp","reoperation","reoperation1","retorpodays","reoporcpt1","retorrelated","reoporicd91","reoperation2","retor2podays","reopor2cpt1","retor2related","reopor2icd91","reoperation3","readmission","readmission1","readmpodays1","unplanreadmission","unplannedreadmission1","readmrelated1","readmsuspreason1","readmrelicd91","readmission2","readmpodays2","unplannedreadmission2","readmrelated2","readmsuspreason2","readmrelicd92","readmission3","readmpodays3","unplannedreadmission3","readmrelated3","readmsuspreason3","readmrelicd93","readmission4","readmpodays4","unplannedreadmission4","readmrelated4","readmsuspreason4","readmrelicd94","readmission5","readmpodays5","unplannedreadmission5","readmrelated5","readmsuspreason5","readmrelicd95","readmunrelsusp1","readmunrelicd91","readmunrelsusp2","readmunrelicd92","readmunrelsusp3","readmunrelicd93","readmunrelsusp4","readmunrelicd94","readmunrelsusp5","readmunrelicd95","podiag10","podiagtx10","reopor1icd101","reopor2icd101","readmrelicd101","readmunrelicd101","readmrelicd102","readmunrelicd102","readmrelicd103","readmunrelicd103","readmrelicd104","readmunrelicd104","readmrelicd105","readmunrelicd105","wound_closure","podiag_other","podiag_other10") +dindo_1 <- c("supinfec","wndinfd","dehis","renainsf") + +dindo_2 <- c("orgspcssi","oupneumo","urninfec","pulembol","othbleed","othdvt","othsysep","othcdiff") + +dindo_3 <- c("returnor") + +dindo_4 <- c("reintub","failwean","oprenafl","cnscva","cdarrest","cdmi","othseshock","cnscoma","neurodef") + +dindo_5 <- c("yrdeath") + +acs_cols <- c("caseid","pufyear","sex","race","race_new","ethnicity_hispanic","prncptx","cpt","workrvu","inout","transt","age","admyr","admsyr","operyr","electsurg","dischdest","anesthes","anesthes_other","attend","surgspec","height","weight","diabetes","insulin","smoke","packs","etoh","dyspnea","when_dyspnea","dnr","fnstatus1","fnstatus2","ventilat","hxcopd","cpneumon","ascites","esovar","hxchf","hxmi","prvpci","prvpcs","hxangina","hypermed","hxpvd","restpain","renafail","dialysis","impsens","coma","hemi","hxtia","cva","cvano","tumorcns","para","quad","discancr","wndinf","steroid","wtloss","bleeddis","transfus","chemo","radio","prsepis","type_prsepis","pregnancy","proper30","dprna","dprbun","dprcreat","dpralbum","dprbili","dprsgot","dpralkph","dprwbc","dprhct","dprplate","dprptt","dprpt","dprinr","prsodm","prbun","prcreat","pralbum","prbili","prsgot","pralkph","prwbc","prhct","prplate","prptt","prinr","prpt","otherproc1","othercpt1","otherwrvu1","otherproc2","othercpt2","otherwrvu2","otherproc3","othercpt3","otherwrvu3","otherproc4","othercpt4","otherwrvu4","otherproc5","othercpt5","otherwrvu5","otherproc6","othercpt6","otherwrvu6","otherproc7","othercpt7","otherwrvu7","otherproc8","othercpt8","otherwrvu8","otherproc9","othercpt9","otherwrvu9","otherproc10","othercpt10","otherwrvu10","concurr1","concpt1","conwrvu1","concurr2","concpt2","conwrvu2","concurr3","concpt3","conwrvu3","concurr4","concpt4","conwrvu4","concurr5","concpt5","conwrvu5","concurr6","concpt6","conwrvu6","concurr7","concpt7","conwrvu7","concurr8","concpt8","conwrvu8","concurr9","concpt9","conwrvu9","concurr10","concpt10","conwrvu10","opnote","pgy","emergncy","wndclas","asaclas","airtra","mallamp","rbc","anesurg","surgane","dpatrm","anetime","optime","typeintoc","sdisdt","hdisdt","yrdeath","tothlos","admqtr","htooday","stooday","totslos","nsupinfec","supinfec","dsupinfec","sssipatos","nwndinfd","wndinfd","dwndinfd","dssipatos","norgspcssi","orgspcssi","dorgspcssi","ossipatos","ndehis","dehis","ddehis","noupneumo","oupneumo","doupneumo","pnapatos","nreintub","reintub","dreintub","npulembol","pulembol","dpulembol","nfailwean","failwean","dfailwean","ventpatos","nrenainsf","renainsf","drenainsf","noprenafl","oprenafl","doprenafl","nurninfec","urninfec","durninfec","utipatos","ncnscva","cnscva","dcnscva","ncnscoma","cnscoma","dcnscoma","nneurodef","neurodef","dneurodef","ncdarrest","cdarrest","dcdarrest","ncdmi","cdmi","dcdmi","nothbleed","othbleed","dothbleed","nothgrafl","othgrafl","dothgrafl","nothdvt","othdvt","dothdvt","nothsysep","othsysep","dothsysep","sepsispatos","nothseshock","othseshock","dothseshock","sepshockpatos","othcdiff","nothcdiff","dothcdiff","podiag","podiagtx","returnor","dsdtohd","dopertod","doptodis","mortprob","morbprob","stillinhosp","reoperation","reoperation1","retorpodays","reoporcpt1","retorrelated","reoporicd91","reoperation2","retor2podays","reopor2cpt1","retor2related","reopor2icd91","reoperation3","readmission","readmission1","readmpodays1","unplanreadmission","unplannedreadmission1","readmrelated1","readmsuspreason1","readmrelicd91","readmission2","readmpodays2","unplannedreadmission2","readmrelated2","readmsuspreason2","readmrelicd92","readmission3","readmpodays3","unplannedreadmission3","readmrelated3","readmsuspreason3","readmrelicd93","readmission4","readmpodays4","unplannedreadmission4","readmrelated4","readmsuspreason4","readmrelicd94","readmission5","readmpodays5","unplannedreadmission5","readmrelated5","readmsuspreason5","readmrelicd95","readmunrelsusp1","readmunrelicd91","readmunrelsusp2","readmunrelicd92","readmunrelsusp3","readmunrelicd93","readmunrelsusp4","readmunrelicd94","readmunrelsusp5","readmunrelicd95","podiag10","podiagtx10","reopor1icd101","reopor2icd101","readmrelicd101","readmunrelicd101","readmrelicd102","readmunrelicd102","readmrelicd103","readmunrelicd103","readmrelicd104","readmunrelicd104","readmrelicd105","readmunrelicd105","dindo","wound_closure","podiag_other","podiag_other10") aaa_cols <- c("aaa_surgind", "aaa_andiam", "aaa_andiam_unk", "aaa_paas", "aaa_surgap", "aaa_pcl", "aaa_pae", "aaa_distext", "aaa_mima", "aaa_cp_renrevasc", "aaa_cp_viscrevasc", "aaa_cp_ler", "aaa_cp_are", "aaa_colitis", "aaa_dcolitis", "aaa_colitiis_treat", "aaa_lei", "aaa_dlei", "aaa_roa", "aaa_droa", "aaa_iculos") diff --git a/R/conv_acs.R b/R/conv_acs.R index a4c7ca2..c780c44 100644 --- a/R/conv_acs.R +++ b/R/conv_acs.R @@ -39,7 +39,8 @@ conv_acs_cols <- function(df) { nothgrafl = tryCatch(conv_dn_comagraftpn(nothgrafl, pufyear), error = function(e) return(NULL)), othgrafl = tryCatch(conv_comagraftpn(othgrafl, pufyear), error = function(e) return(NULL)), dothgrafl = tryCatch(conv_dn_comagraftpn(dothgrafl, pufyear), error = function(e) return(NULL)), - typeintoc = tryCatch(conv_typeintoc(typeintoc), error = function(e) return(NULL)) + typeintoc = tryCatch(conv_typeintoc(typeintoc), error = function(e) return(NULL)), + dindo = dindo(.) ) } diff --git a/R/dindo.R b/R/dindo.R new file mode 100644 index 0000000..cd0dfdc --- /dev/null +++ b/R/dindo.R @@ -0,0 +1,81 @@ +#' 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. +#' +#' @keywords internal +#' +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) +} diff --git a/R/nsqip.R b/R/nsqip.R index 47cfcd4..d15ad5d 100644 --- a/R/nsqip.R +++ b/R/nsqip.R @@ -16,7 +16,7 @@ # TODO If only one type of PUF (i.e. just ACS, just targeted, etc.), then skip making directories. nsqip <- function(path, return_df = TRUE, write_to_csv = FALSE, append = FALSE, headers = TRUE) { - files <- get_file_or_dir(path) + files <- get_file_or_dir(path) # returns a parse_files(files) dirs <- list.dirs(unique(dirname(files)), recursive = FALSE) # This allows this function to work whether the user passes a single file or a directory of files. diff --git a/tests/testthat/test-dindo.R b/tests/testthat/test-dindo.R new file mode 100644 index 0000000..38ca58e --- /dev/null +++ b/tests/testthat/test-dindo.R @@ -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)) +}) From 79b69d4e50e49c5c42a06e0aa073b14ef70ad2c9 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Sat, 29 Aug 2020 21:55:39 -1000 Subject: [PATCH 2/3] modified some dindo stuff and also going to test furniture washer" --- R/conv_standard.R | 1 + R/dindo.R | 7 ++++--- R/nsqip.R | 2 +- man/checkAnyDead.Rd | 18 ++++++++++++++++++ man/checkAnyTrue.Rd | 18 ++++++++++++++++++ man/checkTrue.Rd | 19 +++++++++++++++++++ man/dindo.Rd | 18 ++++++++++++++++++ man/isDead.Rd | 20 ++++++++++++++++++++ 8 files changed, 99 insertions(+), 4 deletions(-) create mode 100644 man/checkAnyDead.Rd create mode 100644 man/checkAnyTrue.Rd create mode 100644 man/checkTrue.Rd create mode 100644 man/dindo.Rd create mode 100644 man/isDead.Rd diff --git a/R/conv_standard.R b/R/conv_standard.R index ea67b2e..81443be 100644 --- a/R/conv_standard.R +++ b/R/conv_standard.R @@ -25,6 +25,7 @@ set_up_df <- function(df, col_names) { df %>% dplyr::rename_with(., tolower) %>% dplyr::mutate(dplyr::across(dplyr::everything(), tolower)) %>% + #dplyr::mutate(dplyr::across(dplyr::everything(), furniture::washer, "unknown", "null", "n/a", "not documented", "none/not documented", "not entered","-99", -99)) %>% NEEDS TO BE TESTED dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "unknown")) %>% dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "null")) %>% dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "n/a")) %>% diff --git a/R/dindo.R b/R/dindo.R index cd0dfdc..e87a277 100644 --- a/R/dindo.R +++ b/R/dindo.R @@ -52,13 +52,14 @@ checkAnyDead <- function(...) { 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. +#' @param df a dataframe including relevant columns containing information on specific post-operative complications. #' -#' @return a numeric vector representing the Dindo-Clavien classification. +#' @return a numeric vector representing the Dindo-Clavien classification. #' -#' @keywords internal +#' @keywords internal #' dindo <- function(df) { e <- new.env() diff --git a/R/nsqip.R b/R/nsqip.R index d15ad5d..47cfcd4 100644 --- a/R/nsqip.R +++ b/R/nsqip.R @@ -16,7 +16,7 @@ # TODO If only one type of PUF (i.e. just ACS, just targeted, etc.), then skip making directories. nsqip <- function(path, return_df = TRUE, write_to_csv = FALSE, append = FALSE, headers = TRUE) { - files <- get_file_or_dir(path) # returns a + files <- get_file_or_dir(path) parse_files(files) dirs <- list.dirs(unique(dirname(files)), recursive = FALSE) # This allows this function to work whether the user passes a single file or a directory of files. diff --git a/man/checkAnyDead.Rd b/man/checkAnyDead.Rd new file mode 100644 index 0000000..15ce832 --- /dev/null +++ b/man/checkAnyDead.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dindo.R +\name{checkAnyDead} +\alias{checkAnyDead} +\title{Check if any trues exist row-wise in a logical matrix.} +\usage{ +checkAnyDead(...) +} +\arguments{ +\item{...}{a list of vectors of any type or a data frame} +} +\value{ +a logical vector. TRUE if any NA values in row, FALSE if no NA values in row. +} +\description{ +Check if any trues exist row-wise in a logical matrix. +} +\keyword{internal} diff --git a/man/checkAnyTrue.Rd b/man/checkAnyTrue.Rd new file mode 100644 index 0000000..629dd23 --- /dev/null +++ b/man/checkAnyTrue.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dindo.R +\name{checkAnyTrue} +\alias{checkAnyTrue} +\title{Check if any trues exist row-wise in a logical matrix.} +\usage{ +checkAnyTrue(...) +} +\arguments{ +\item{...}{a list of logical vectors or a data frame} +} +\value{ +a logical vector. TRUE if any trues, FALSE if no trues. +} +\description{ +Check if any trues exist row-wise in a logical matrix. +} +\keyword{internal} diff --git a/man/checkTrue.Rd b/man/checkTrue.Rd new file mode 100644 index 0000000..b1f83de --- /dev/null +++ b/man/checkTrue.Rd @@ -0,0 +1,19 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dindo.R +\name{checkTrue} +\alias{checkTrue} +\title{Check if a boolean is TRUE and not NA} +\usage{ +checkTrue(bool) +} +\arguments{ +\item{bool}{a logical vector} +} +\value{ +a logical vector +} +\description{ +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. +} +\keyword{internal} diff --git a/man/dindo.Rd b/man/dindo.Rd new file mode 100644 index 0000000..d7fee4c --- /dev/null +++ b/man/dindo.Rd @@ -0,0 +1,18 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dindo.R +\name{dindo} +\alias{dindo} +\title{Classifies a patient according to the Dindo-Clavien surgical complication grading scale.} +\usage{ +dindo(df) +} +\arguments{ +\item{df}{a dataframe including relevant columns containing information on specific post-operative complications.} +} +\value{ +a numeric vector representing the Dindo-Clavien classification. +} +\description{ +Classifies a patient according to the Dindo-Clavien surgical complication grading scale. +} +\keyword{internal} diff --git a/man/isDead.Rd b/man/isDead.Rd new file mode 100644 index 0000000..4990b6b --- /dev/null +++ b/man/isDead.Rd @@ -0,0 +1,20 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/dindo.R +\name{isDead} +\alias{isDead} +\title{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 \code{yrdeath}.} +\usage{ +isDead(col) +} +\arguments{ +\item{col}{a vector of any type} +} +\value{ +a logical vector. TRUE if not NA, FALSE if NA. +} +\description{ +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 \code{yrdeath}. +} +\keyword{internal} From bf27329f244b268fb37e94484895609c5e32ab68 Mon Sep 17 00:00:00 2001 From: Dylan Russell Date: Wed, 2 Sep 2020 14:24:07 -1000 Subject: [PATCH 3/3] ready for merge to master --- DESCRIPTION | 79 +++++++++++++++++++++++---------------------- NAMESPACE | 1 + R/col_definitions.R | 4 ++- R/conv_acs.R | 3 +- R/conv_standard.R | 10 +----- R/dindo.R | 2 +- man/dindo.Rd | 1 - 7 files changed, 47 insertions(+), 53 deletions(-) diff --git a/DESCRIPTION b/DESCRIPTION index 6ed2ea5..33b5f3c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -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 = "dyl.russell@gmail.com", - 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 = "dyl.russell@gmail.com", + 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) diff --git a/NAMESPACE b/NAMESPACE index b5133d6..46d6556 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -1,5 +1,6 @@ # Generated by roxygen2: do not edit by hand +export(dindo) export(nsqip) importFrom("utils","file_test") importFrom(magrittr,"%>%") diff --git a/R/col_definitions.R b/R/col_definitions.R index 561036a..ec9a907 100644 --- a/R/col_definitions.R +++ b/R/col_definitions.R @@ -24,7 +24,7 @@ dindo_4 <- c("reintub","failwean","oprenafl","cnscva","cdarrest","cdmi","othsesh dindo_5 <- c("yrdeath") -acs_cols <- c("caseid","pufyear","sex","race","race_new","ethnicity_hispanic","prncptx","cpt","workrvu","inout","transt","age","admyr","admsyr","operyr","electsurg","dischdest","anesthes","anesthes_other","attend","surgspec","height","weight","diabetes","insulin","smoke","packs","etoh","dyspnea","when_dyspnea","dnr","fnstatus1","fnstatus2","ventilat","hxcopd","cpneumon","ascites","esovar","hxchf","hxmi","prvpci","prvpcs","hxangina","hypermed","hxpvd","restpain","renafail","dialysis","impsens","coma","hemi","hxtia","cva","cvano","tumorcns","para","quad","discancr","wndinf","steroid","wtloss","bleeddis","transfus","chemo","radio","prsepis","type_prsepis","pregnancy","proper30","dprna","dprbun","dprcreat","dpralbum","dprbili","dprsgot","dpralkph","dprwbc","dprhct","dprplate","dprptt","dprpt","dprinr","prsodm","prbun","prcreat","pralbum","prbili","prsgot","pralkph","prwbc","prhct","prplate","prptt","prinr","prpt","otherproc1","othercpt1","otherwrvu1","otherproc2","othercpt2","otherwrvu2","otherproc3","othercpt3","otherwrvu3","otherproc4","othercpt4","otherwrvu4","otherproc5","othercpt5","otherwrvu5","otherproc6","othercpt6","otherwrvu6","otherproc7","othercpt7","otherwrvu7","otherproc8","othercpt8","otherwrvu8","otherproc9","othercpt9","otherwrvu9","otherproc10","othercpt10","otherwrvu10","concurr1","concpt1","conwrvu1","concurr2","concpt2","conwrvu2","concurr3","concpt3","conwrvu3","concurr4","concpt4","conwrvu4","concurr5","concpt5","conwrvu5","concurr6","concpt6","conwrvu6","concurr7","concpt7","conwrvu7","concurr8","concpt8","conwrvu8","concurr9","concpt9","conwrvu9","concurr10","concpt10","conwrvu10","opnote","pgy","emergncy","wndclas","asaclas","airtra","mallamp","rbc","anesurg","surgane","dpatrm","anetime","optime","typeintoc","sdisdt","hdisdt","yrdeath","tothlos","admqtr","htooday","stooday","totslos","nsupinfec","supinfec","dsupinfec","sssipatos","nwndinfd","wndinfd","dwndinfd","dssipatos","norgspcssi","orgspcssi","dorgspcssi","ossipatos","ndehis","dehis","ddehis","noupneumo","oupneumo","doupneumo","pnapatos","nreintub","reintub","dreintub","npulembol","pulembol","dpulembol","nfailwean","failwean","dfailwean","ventpatos","nrenainsf","renainsf","drenainsf","noprenafl","oprenafl","doprenafl","nurninfec","urninfec","durninfec","utipatos","ncnscva","cnscva","dcnscva","ncnscoma","cnscoma","dcnscoma","nneurodef","neurodef","dneurodef","ncdarrest","cdarrest","dcdarrest","ncdmi","cdmi","dcdmi","nothbleed","othbleed","dothbleed","nothgrafl","othgrafl","dothgrafl","nothdvt","othdvt","dothdvt","nothsysep","othsysep","dothsysep","sepsispatos","nothseshock","othseshock","dothseshock","sepshockpatos","othcdiff","nothcdiff","dothcdiff","podiag","podiagtx","returnor","dsdtohd","dopertod","doptodis","mortprob","morbprob","stillinhosp","reoperation","reoperation1","retorpodays","reoporcpt1","retorrelated","reoporicd91","reoperation2","retor2podays","reopor2cpt1","retor2related","reopor2icd91","reoperation3","readmission","readmission1","readmpodays1","unplanreadmission","unplannedreadmission1","readmrelated1","readmsuspreason1","readmrelicd91","readmission2","readmpodays2","unplannedreadmission2","readmrelated2","readmsuspreason2","readmrelicd92","readmission3","readmpodays3","unplannedreadmission3","readmrelated3","readmsuspreason3","readmrelicd93","readmission4","readmpodays4","unplannedreadmission4","readmrelated4","readmsuspreason4","readmrelicd94","readmission5","readmpodays5","unplannedreadmission5","readmrelated5","readmsuspreason5","readmrelicd95","readmunrelsusp1","readmunrelicd91","readmunrelsusp2","readmunrelicd92","readmunrelsusp3","readmunrelicd93","readmunrelsusp4","readmunrelicd94","readmunrelsusp5","readmunrelicd95","podiag10","podiagtx10","reopor1icd101","reopor2icd101","readmrelicd101","readmunrelicd101","readmrelicd102","readmunrelicd102","readmrelicd103","readmunrelicd103","readmrelicd104","readmunrelicd104","readmrelicd105","readmunrelicd105","dindo","wound_closure","podiag_other","podiag_other10") +acs_cols <- c("caseid","pufyear","sex","race","race_new","ethnicity_hispanic","prncptx","cpt","workrvu","inout","transt","age","admyr","admsyr","operyr","electsurg","dischdest","anesthes","anesthes_other","attend","surgspec","height","weight","diabetes","insulin","smoke","packs","etoh","dyspnea","when_dyspnea","dnr","fnstatus1","fnstatus2","ventilat","hxcopd","cpneumon","ascites","esovar","hxchf","hxmi","prvpci","prvpcs","hxangina","hypermed","hxpvd","restpain","renafail","dialysis","impsens","coma","hemi","hxtia","cva","cvano","tumorcns","para","quad","discancr","wndinf","steroid","wtloss","bleeddis","transfus","chemo","radio","prsepis","type_prsepis","pregnancy","proper30","dprna","dprbun","dprcreat","dpralbum","dprbili","dprsgot","dpralkph","dprwbc","dprhct","dprplate","dprptt","dprpt","dprinr","prsodm","prbun","prcreat","pralbum","prbili","prsgot","pralkph","prwbc","prhct","prplate","prptt","prinr","prpt","otherproc1","othercpt1","otherwrvu1","otherproc2","othercpt2","otherwrvu2","otherproc3","othercpt3","otherwrvu3","otherproc4","othercpt4","otherwrvu4","otherproc5","othercpt5","otherwrvu5","otherproc6","othercpt6","otherwrvu6","otherproc7","othercpt7","otherwrvu7","otherproc8","othercpt8","otherwrvu8","otherproc9","othercpt9","otherwrvu9","otherproc10","othercpt10","otherwrvu10","concurr1","concpt1","conwrvu1","concurr2","concpt2","conwrvu2","concurr3","concpt3","conwrvu3","concurr4","concpt4","conwrvu4","concurr5","concpt5","conwrvu5","concurr6","concpt6","conwrvu6","concurr7","concpt7","conwrvu7","concurr8","concpt8","conwrvu8","concurr9","concpt9","conwrvu9","concurr10","concpt10","conwrvu10","opnote","pgy","emergncy","wndclas","asaclas","airtra","mallamp","rbc","anesurg","surgane","dpatrm","anetime","optime","typeintoc","sdisdt","hdisdt","yrdeath","tothlos","admqtr","htooday","stooday","totslos","nsupinfec","supinfec","dsupinfec","sssipatos","nwndinfd","wndinfd","dwndinfd","dssipatos","norgspcssi","orgspcssi","dorgspcssi","ossipatos","ndehis","dehis","ddehis","noupneumo","oupneumo","doupneumo","pnapatos","nreintub","reintub","dreintub","npulembol","pulembol","dpulembol","nfailwean","failwean","dfailwean","ventpatos","nrenainsf","renainsf","drenainsf","noprenafl","oprenafl","doprenafl","nurninfec","urninfec","durninfec","utipatos","ncnscva","cnscva","dcnscva","ncnscoma","cnscoma","dcnscoma","nneurodef","neurodef","dneurodef","ncdarrest","cdarrest","dcdarrest","ncdmi","cdmi","dcdmi","nothbleed","othbleed","dothbleed","nothgrafl","othgrafl","dothgrafl","nothdvt","othdvt","dothdvt","nothsysep","othsysep","dothsysep","sepsispatos","nothseshock","othseshock","dothseshock","sepshockpatos","othcdiff","nothcdiff","dothcdiff","podiag","podiagtx","returnor","dsdtohd","dopertod","doptodis","mortprob","morbprob","stillinhosp","reoperation","reoperation1","retorpodays","reoporcpt1","retorrelated","reoporicd91","reoperation2","retor2podays","reopor2cpt1","retor2related","reopor2icd91","reoperation3","readmission","readmission1","readmpodays1","unplanreadmission","unplannedreadmission1","readmrelated1","readmsuspreason1","readmrelicd91","readmission2","readmpodays2","unplannedreadmission2","readmrelated2","readmsuspreason2","readmrelicd92","readmission3","readmpodays3","unplannedreadmission3","readmrelated3","readmsuspreason3","readmrelicd93","readmission4","readmpodays4","unplannedreadmission4","readmrelated4","readmsuspreason4","readmrelicd94","readmission5","readmpodays5","unplannedreadmission5","readmrelated5","readmsuspreason5","readmrelicd95","readmunrelsusp1","readmunrelicd91","readmunrelsusp2","readmunrelicd92","readmunrelsusp3","readmunrelicd93","readmunrelsusp4","readmunrelicd94","readmunrelsusp5","readmunrelicd95","podiag10","podiagtx10","reopor1icd101","reopor2icd101","readmrelicd101","readmunrelicd101","readmrelicd102","readmunrelicd102","readmrelicd103","readmunrelicd103","readmrelicd104","readmunrelicd104","readmrelicd105","readmunrelicd105","wound_closure","podiag_other","podiag_other10") aaa_cols <- c("aaa_surgind", "aaa_andiam", "aaa_andiam_unk", "aaa_paas", "aaa_surgap", "aaa_pcl", "aaa_pae", "aaa_distext", "aaa_mima", "aaa_cp_renrevasc", "aaa_cp_viscrevasc", "aaa_cp_ler", "aaa_cp_are", "aaa_colitis", "aaa_dcolitis", "aaa_colitiis_treat", "aaa_lei", "aaa_dlei", "aaa_roa", "aaa_droa", "aaa_iculos") @@ -32,4 +32,6 @@ aie_cols <- c("aie_proc", "aie_sympt", "aie_hrf_phys", "aie_hrf_anat", "aie_prem col_cols <- c("col_steroid","col_steroid_unk","col_mech_bowel_prep","col_mech_bowel_prep_unk","col_oral_antibiotic","col_oral_antibiotic_unk","col_chemo","col_chemo_unk","col_indication","col_icd9_indication","col_emergent","col_icd9_emergent","col_approach","col_open_assist","col_unplanned_conversion","col_margins","col_margins_unk","col_malignancyt","col_malignancyn","col_malignancym","col_anastomotic","col_leak_treatment","col_ileus","col_ileus_unk","col_nodeseval","col_icd10_indication","col_icd10_emergent") +add_cols <- c("dindo") + col_order <- c(acs_cols, aaa_cols, aie_cols, col_cols) diff --git a/R/conv_acs.R b/R/conv_acs.R index c780c44..a4c7ca2 100644 --- a/R/conv_acs.R +++ b/R/conv_acs.R @@ -39,8 +39,7 @@ conv_acs_cols <- function(df) { nothgrafl = tryCatch(conv_dn_comagraftpn(nothgrafl, pufyear), error = function(e) return(NULL)), othgrafl = tryCatch(conv_comagraftpn(othgrafl, pufyear), error = function(e) return(NULL)), dothgrafl = tryCatch(conv_dn_comagraftpn(dothgrafl, pufyear), error = function(e) return(NULL)), - typeintoc = tryCatch(conv_typeintoc(typeintoc), error = function(e) return(NULL)), - dindo = dindo(.) + typeintoc = tryCatch(conv_typeintoc(typeintoc), error = function(e) return(NULL)) ) } diff --git a/R/conv_standard.R b/R/conv_standard.R index 81443be..c74f1df 100644 --- a/R/conv_standard.R +++ b/R/conv_standard.R @@ -25,15 +25,7 @@ set_up_df <- function(df, col_names) { df %>% dplyr::rename_with(., tolower) %>% dplyr::mutate(dplyr::across(dplyr::everything(), tolower)) %>% - #dplyr::mutate(dplyr::across(dplyr::everything(), furniture::washer, "unknown", "null", "n/a", "not documented", "none/not documented", "not entered","-99", -99)) %>% NEEDS TO BE TESTED - dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "unknown")) %>% - dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "null")) %>% - dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "n/a")) %>% - dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "not documented")) %>% - dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "none/not documented")) %>% - dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "not entered")) %>% - dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, "-99")) %>% - dplyr::mutate(dplyr::across(dplyr::everything(), dplyr::na_if, -99)) %>% + dplyr::mutate(dplyr::across(dplyr::everything(), furniture::washer, "unknown", "null", "n/a", "not documented", "none/not documented", "not entered","-99", -99)) %>% tibble::add_column(., !!!col_names[setdiff(names(col_names), names(.))]) } diff --git a/R/dindo.R b/R/dindo.R index e87a277..f715212 100644 --- a/R/dindo.R +++ b/R/dindo.R @@ -59,7 +59,7 @@ checkAnyDead <- function(...) { #' #' @return a numeric vector representing the Dindo-Clavien classification. #' -#' @keywords internal +#' @export #' dindo <- function(df) { e <- new.env() diff --git a/man/dindo.Rd b/man/dindo.Rd index d7fee4c..7a67f04 100644 --- a/man/dindo.Rd +++ b/man/dindo.Rd @@ -15,4 +15,3 @@ a numeric vector representing the Dindo-Clavien classification. \description{ Classifies a patient according to the Dindo-Clavien surgical complication grading scale. } -\keyword{internal}