Skip to content

Commit

Permalink
change mutate_if example in na_if documentation to mutate across (#…
Browse files Browse the repository at this point in the history
…5516)

* change mutate_if example in na_if doc to mutate   across

* use na_if() and document()

Co-authored-by: Romain Francois <[email protected]>
  • Loading branch information
rivaquiroga and romainfrancois authored Sep 2, 2020
1 parent 745c9a6 commit 134c871
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
8 changes: 4 additions & 4 deletions R/na_if.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 24,16 @@
#' y <- c("abc", "def", "", "ghi")
#' na_if(y, "")
#'
#' # na_if is particularly useful inside mutate,
#' # na_if() is particularly useful inside mutate(),
#' # and is meant for use with vectors rather than entire data frames
#' starwars %>%
#' select(name, eye_color) %>%
#' mutate(eye_color = na_if(eye_color, "unknown"))
#'
#' # na_if can also be used with scoped variants of mutate
#' # like mutate_if to mutate multiple columns
#' # na_if() can also be used with mutate() and across()
#' # to mutate multiple columns
#' starwars %>%
#' mutate_if(is.character, list(~na_if(., "unknown")))
#' mutate(across(where(is.character), ~na_if(., "unknown")))
na_if <- function(x, y) {
check_length(y, x, fmt_args("y"), glue("same as {fmt_args(~x)}"))

Expand Down
3 changes: 1 addition & 2 deletions man/dplyr-package.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 4 additions & 4 deletions man/na_if.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 134c871

Please sign in to comment.