From 29a32aa7f3ce98262ff3e5a74772a7f07b347c12 Mon Sep 17 00:00:00 2001 From: JoFrhwld Date: Tue, 26 Sep 2023 16:03:41 -0400 Subject: [PATCH] na_filter filters missing values out of paired vectors --- R/helper_funs.R | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/R/helper_funs.R b/R/helper_funs.R index 80f7ce4..1438653 100644 --- a/R/helper_funs.R +++ b/R/helper_funs.R @@ -22,3 +22,30 @@ xyz_to_isolines <- function(data, breaks) { levels = breaks[-length(breaks)] ) } + +na_filter <- function(...){ + + dots <- rlang::dots_list(...) + dots_name <- names(dots) + + na_vec <- purrr::map(dots, is.na) + + if(purrr::reduce(na_vec, any)){ + na_loc <- purrr::reduce(na_vec, `|`) + new_values <- purrr::map(dots, \(x)x[!na_loc]) + output <- list( + filtered = TRUE, + values = new_values, + total = purrr::map(na_vec, sum) + ) + }else{ + output <- list( + filtered = FALSE, + values = dots, + total = purrr::map(na_vec, sum) + ) + } + + return(output) + +}