Skip to content

Commit

Permalink
na_filter filters missing values out of paired vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
JoFrhwld committed Sep 26, 2023
1 parent bf83cf3 commit 29a32aa
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions R/helper_funs.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)

}

0 comments on commit 29a32aa

Please sign in to comment.