Skip to content

Commit

Permalink
Merge pull request #9 from JoFrhwld/na_filter
Browse files Browse the repository at this point in the history
Na filter
  • Loading branch information
JoFrhwld authored Sep 26, 2023
2 parents 8a094b3 + dab207f commit 0d69f4d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
17 changes: 17 additions & 0 deletions R/density_area.R
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,23 @@ density_polygons <- function(x,
repair = "unique",
quiet = TRUE)

na_filtered <- na_filter(x = x, y = y)

if(na_filtered$filtered){
x = na_filtered$values$x
y = na_filtered$values$y

x_total <- na_filtered$total$x
y_total <- na_filtered$total$y
cli::cli_warn(
c("Missing values dropped",
"i" = "{x_total} missing value{?s} in {xname}",
"i" = "{y_total} missing value{?s} in {yname}"
)
)
}


isolines <- get_isolines_safely(x=x, y=y, probs=probs, ...)

isolines |>
Expand Down
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 0d69f4d

Please sign in to comment.