Skip to content

Commit

Permalink
Add rename_with() example of using paste0(recycle0 = TRUE) (#6690)
Browse files Browse the repository at this point in the history
* Add an example of `recycle0`

* NEWS bullet
  • Loading branch information
DavisVaughan authored Feb 7, 2023
1 parent 8610ce5 commit e8702df
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
3 changes: 3 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# dplyr (development version)

* `rename_with()` now includes an example of using `paste0(recycle0 = TRUE)` to
correctly handle empty selections (#6688).

# dplyr 1.1.0

## New features
Expand Down
15 changes: 15 additions & 0 deletions R/rename.R
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,21 @@
#' rename_with(iris, toupper)
#' rename_with(iris, toupper, starts_with("Petal"))
#' rename_with(iris, ~ tolower(gsub(".", "_", .x, fixed = TRUE)))
#'
#' @examplesIf getRversion() > "4.0.1"
#' # If your renaming function uses `paste0()`, make sure to set
#' # `recycle0 = TRUE` to ensure that empty selections are recycled correctly
#' try(rename_with(
#' iris,
#' ~ paste0("prefix_", .x),
#' starts_with("nonexistent")
#' ))
#'
#' rename_with(
#' iris,
#' ~ paste0("prefix_", .x, recycle0 = TRUE),
#' starts_with("nonexistent")
#' )
#' @export
rename <- function(.data, ...) {
UseMethod("rename")
Expand Down
16 changes: 16 additions & 0 deletions man/rename.Rd

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

0 comments on commit e8702df

Please sign in to comment.