From 4457547c61eccb9e8af2c1fced0b9eff9368500c Mon Sep 17 00:00:00 2001 From: Will Beasley Date: Sat, 28 Oct 2023 12:10:04 -0500 Subject: [PATCH] `row_sum()` checks ref #126 --- NAMESPACE | 1 + R/row.R | 17 +++++++++++++---- inst/WORDLIST | 1 + man/row_sum.Rd | 4 ++-- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 0a85b23..5e94663 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -48,6 +48,7 @@ export(update_packages_addin) export(upload_sqls_odbc) export(verify_value_headstart) importFrom(magrittr,"%>%") +importFrom(rlang,":=") importFrom(rlang,.data) importFrom(utils,capture.output) importFrom(utils,installed.packages) diff --git a/R/row.R b/R/row.R index 9357e27..6008259 100644 --- a/R/row.R +++ b/R/row.R @@ -17,7 +17,7 @@ #' @param threshold_proportion Designates the minimum proportion of columns #' that have a nonmissing values (within each row) in order to return a sum. #' Required; defaults to to 0.75. -#' @param vebose a logical value to designate if extra information is +#' @param vv a logical value to designate if extra information is #' displayed in the console, #' such as which columns are matched by `pattern`. #' @@ -30,6 +30,7 @@ #' #' @note #' @author Will Beasley +#' @importFrom rlang := #' @examples #' library(OuhscMunge) #Load the package into the current R session. @@ -41,8 +42,16 @@ row_sum <- function( pattern, new_column_name = "row_sum", threshold_proportion = .75, - verbose = FALSE + vv = FALSE ) { + checkmate::assert_data_frame(d) + checkmate::assert_character(columns_to_average , any.missing = FALSE) + checkmate::assert_character(pattern , min.len = 0, max.len = 1) + checkmate::assert_character(new_column_name , len = 1) + checkmate::assert_double( threshold_proportion, len = 1) + checkmate::assert_logical( vv , len = 1) + + if (length(columns_to_average) == 0L) { columns_to_average <- @@ -55,7 +64,7 @@ row_sum <- function( perl = TRUE ) - if (verbose) { + if (vv) { message( "The following columns will be summed:\n- ", paste(columns_to_average, collapse = "\n- ") @@ -72,7 +81,7 @@ row_sum <- function( } ) - rs <- nonmissing_count <- NULL + rs <- nonmissing_count <- nonmissing_proportion <- NULL d <- d |> dplyr::mutate( diff --git a/inst/WORDLIST b/inst/WORDLIST index 7cf1526..0a2bfae 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -43,6 +43,7 @@ lettercase libcurl mrn nonmissing +nonmissingness odbc openssl patientdob diff --git a/man/row_sum.Rd b/man/row_sum.Rd index 061712e..3ccd138 100644 --- a/man/row_sum.Rd +++ b/man/row_sum.Rd @@ -10,7 +10,7 @@ row_sum( pattern, new_column_name = "row_sum", threshold_proportion = 0.75, - verbose = FALSE + vv = FALSE ) } \arguments{ @@ -30,7 +30,7 @@ of the specified columns. Required.} that have a nonmissing values (within each row) in order to return a sum. Required; defaults to to 0.75.} -\item{vebose}{a logical value to designate if extra information is +\item{vv}{a logical value to designate if extra information is displayed in the console, such as which columns are matched by \code{pattern}.} }