Skip to content

Commit

Permalink
Document how to pass dots to select_vars()
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed May 4, 2017
1 parent 110b1aa commit c1813b9
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
21 changes: 21 additions & 0 deletions R/select-vars.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@
#'
#' These functions power [select()] and [rename()].
#'
#' For historic reasons, the `vars` and `include` arguments are not
#' prefixed with `.`. This means that any argument starting with `v`
#' might partial-match on `vars` if it is not explicitly named. Also
#' `...` cannot accept arguments named `exclude` or `include`. You can
#' enquose and splice the dots to work around these limitations (see
#' examples).
#'
#' @param vars A character vector of existing column names.
#' @param ...,args Expressions to compute
#'
Expand Down Expand Up @@ -61,6 +68,20 @@
#' # However it isn't available within calls since those are evaluated
#' # outside of the data context. This would fail if run:
#' # select_vars(names(mtcars), identical(.data$cyl))
#'
#'
#' # If you're writing a wrapper around select_vars(), pass the dots
#' # via splicing to avoid matching dotted arguments to select_vars()
#' # named arguments (`vars`, `include` and `exclude`):
#' wrapper <- function(...) {
#' select_vars(names(mtcars), !!! quos(...))
#' }
#'
#' # This won't partial-match on `vars`:
#' wrapper(var = cyl)
#'
#' # This won't match on `include`:
#' wrapper(include = cyl)
select_vars <- function(vars, ..., include = character(), exclude = character()) {
quos <- quos(...)

Expand Down
22 changes: 22 additions & 0 deletions man/select_vars.Rd

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

0 comments on commit c1813b9

Please sign in to comment.