Skip to content

Commit

Permalink
Use tidyselect
Browse files Browse the repository at this point in the history
  • Loading branch information
lionel- committed Jul 10, 2017
1 parent 4bb35fb commit 4a07553
Show file tree
Hide file tree
Showing 19 changed files with 166 additions and 677 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Type: Package
Package: dplyr
Version: 0.7.1.9000
Version: 0.7.1.9001
Title: A Grammar of Data Manipulation
Description: A fast, consistent tool for working with data frame like objects,
both in memory and out of memory.
Expand Down
14 changes: 14 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,9 @@ export(ungroup)
export(union)
export(union_all)
export(vars)
export(vars_pull)
export(vars_rename)
export(vars_select)
export(with_order)
export(wrap_dbplyr_obj)
import(rlang)
Expand Down Expand Up @@ -430,6 +433,17 @@ importFrom(tibble,tibble)
importFrom(tibble,tribble)
importFrom(tibble,trunc_mat)
importFrom(tibble,type_sum)
importFrom(tidyselect,contains)
importFrom(tidyselect,current_vars)
importFrom(tidyselect,ends_with)
importFrom(tidyselect,everything)
importFrom(tidyselect,matches)
importFrom(tidyselect,num_range)
importFrom(tidyselect,one_of)
importFrom(tidyselect,starts_with)
importFrom(tidyselect,vars_pull)
importFrom(tidyselect,vars_rename)
importFrom(tidyselect,vars_select)
importFrom(utils,head)
importFrom(utils,tail)
useDynLib(dplyr, .registration = TRUE)
7 changes: 7 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# dplyr 0.7.1.9000

* dplyr now depends on the new tidyselect package to power `select()`,
`rename()`, `pull()` and their variants (#2896). Consequently
`select_vars()`, `select_var()` and `rename_vars()` are
soft-deprecated and will start issuing warnings in the next version.


# dplyr 0.7.1

* Use new versions of bindrcpp and glue to avoid protection problems.
Expand All @@ -20,6 +26,7 @@
* Quosured symbols do not prevent hybrid handling anymore. This should
fix many performance issues introduced with tidyeval (#2822).


# dplyr 0.7.0

## New data, functions, and features
Expand Down
4 changes: 2 additions & 2 deletions R/colwise-mutate.R
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ summarise_each_ <- function(tbl, funs, vars) {
} else {
inform(glue(msg, "\nTo map `funs` over a selection of variables, use `summarise_at()`"))
vars <- compat_lazy_dots(vars, caller_env())
vars <- select_vars(tbl_nongroup_vars(tbl), !!! vars)
vars <- tidyselect::vars_select(tbl_nongroup_vars(tbl), !!! vars)
}
if (is_character(funs)) {
funs <- funs_(funs)
Expand Down Expand Up @@ -254,7 +254,7 @@ mutate_each_ <- function(tbl, funs, vars) {
} else {
inform(glue(msg, "\nTo map `funs` over a selection of variables, use `mutate_at()`"))
vars <- compat_lazy_dots(vars, caller_env())
vars <- select_vars(tbl_nongroup_vars(tbl), !!! vars)
vars <- tidyselect::vars_select(tbl_nongroup_vars(tbl), !!! vars)
}
funs <- manip_apply_syms(funs, syms(vars), tbl)
mutate(tbl, !!! funs)
Expand Down
4 changes: 2 additions & 2 deletions R/colwise.R
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#'
#' * Verbs suffixed with `_at()` apply an operation on a subset of
#' variables specified with the quoting function [vars()]. This
#' quoting function accepts [select_vars()] helpers like
#' quoting function accepts [tidyselect::vars_select()] helpers like
#' [starts_with()]. Instead of a [vars()] selection, you can also
#' supply an [integerish][rlang::is_integerish] vector of column
#' positions or a character vector of column names.
Expand Down Expand Up @@ -127,7 +127,7 @@ tbl_at_vars <- function(tbl, vars) {
} else if (is_integerish(vars)) {
tibble_vars[vars]
} else if (is_quosures(vars)) {
out <- select_vars(tibble_vars, !!! vars)
out <- tidyselect::vars_select(tibble_vars, !!! vars)
if (!any(have_name(vars))) {
names(out) <- NULL
}
Expand Down
6 changes: 3 additions & 3 deletions R/dataframe.R
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ arrange_.data.frame <- function(.data, ..., .dots = list()) {

#' @export
select.data.frame <- function(.data, ...) {
# Pass via splicing to avoid matching select_vars() arguments
vars <- select_vars(names(.data), !!! quos(...))
# Pass via splicing to avoid matching vars_select() arguments
vars <- tidyselect::vars_select(names(.data), !!! quos(...))
select_impl(.data, vars)
}
#' @export
Expand All @@ -120,7 +120,7 @@ select_.data.frame <- function(.data, ..., .dots = list()) {

#' @export
rename.data.frame <- function(.data, ...) {
vars <- rename_vars(names(.data), !!! quos(...))
vars <- tidyselect::vars_rename(names(.data), !!! quos(...))
select_impl(.data, vars)
}
#' @export
Expand Down
6 changes: 3 additions & 3 deletions R/grouped-df.r
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,8 @@ cbind.grouped_df <- function(...) {

#' @export
select.grouped_df <- function(.data, ...) {
# Pass via splicing to avoid matching select_vars() arguments
vars <- select_vars(names(.data), !!! quos(...))
# Pass via splicing to avoid matching vars_select() arguments
vars <- tidyselect::vars_select(names(.data), !!! quos(...))
vars <- ensure_group_vars(vars, .data)
select_impl(.data, vars)
}
Expand Down Expand Up @@ -148,7 +148,7 @@ ensure_group_vars <- function(vars, data, notify = TRUE) {

#' @export
rename.grouped_df <- function(.data, ...) {
vars <- rename_vars(names(.data), !!! quos(...))
vars <- tidyselect::vars_rename(names(.data), !!! quos(...))
select_impl(.data, vars)
}
#' @export
Expand Down
6 changes: 3 additions & 3 deletions R/pull.R
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#' before indexing for remote data tables.
#'
#' @param .data A table of data
#' @inheritParams select_var
#' @inheritParams tidyselect::vars_pull
#' @export
#' @examples
#' mtcars %>% pull(-1)
Expand All @@ -24,11 +24,11 @@ pull <- function(.data, var = -1) {
}
#' @export
pull.data.frame <- function(.data, var = -1) {
var <- select_var(names(.data), !! enquo(var))
var <- tidyselect::vars_pull(names(.data), !! enquo(var))
.data[[var]]
}

# FIXME: remove this once dbplyr uses select_var()
# FIXME: remove this once dbplyr uses vars_pull()
find_var <- function(expr, vars) {
var_env <- set_names(as.list(seq_along(vars)), vars)
var <- eval_tidy(expr, var_env)
Expand Down
84 changes: 84 additions & 0 deletions R/reexport-tidyselect.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@

#' @importFrom tidyselect vars_select
#' @export
tidyselect::vars_select
#' @importFrom tidyselect vars_rename
#' @export
tidyselect::vars_rename
#' @importFrom tidyselect vars_pull
#' @export
tidyselect::vars_pull

#' @importFrom tidyselect current_vars
#' @export
tidyselect::current_vars

#' @importFrom tidyselect contains
#' @export
tidyselect::contains
#' @importFrom tidyselect ends_with
#' @export
tidyselect::ends_with
#' @importFrom tidyselect everything
#' @export
tidyselect::everything
#' @importFrom tidyselect matches
#' @export
tidyselect::matches
#' @importFrom tidyselect num_range
#' @export
tidyselect::num_range
#' @importFrom tidyselect one_of
#' @export
tidyselect::one_of
#' @importFrom tidyselect starts_with
#' @export
tidyselect::starts_with


#' Select variables
#'
#' These functions now live in the tidyselect package as
#' [tidyselect::vars_select()], [tidyselect::vars_rename()] and
#' [tidyselect::vars_pull()]. These dplyr aliases will be deprecated
#' sometimes in the future.
#'
#' @param vars A character vector of existing column names.
#' @param ... Expressions to compute.
#' @param include,exclude Character vector of column names to always
#' include/exclude.
#' @param strict If `TRUE`, will throw an error if you attempt to
#' rename a variable that doesn't exist.
#' @param var A variable specified as in the same argument of
#' [tidyselect::vars_pull()].
#' @export
select_vars <- function(vars, ..., include = chr(), exclude = chr()) {
tidyselect::vars_select(.vars = vars, ..., .include = include, .exclude = exclude)
}
#' @rdname select_vars
#' @inheritParams tidyselect::vars_rename
#' @export
rename_vars <- function(vars, ..., strict = TRUE) {
tidyselect::vars_rename(.vars = vars, ..., .strict = strict)
}
#' @rdname select_vars
#' @inheritParams tidyselect::vars_pull
#' @export
select_var <- function(vars, var = -1) {
tidyselect::vars_pull(vars, !! enquo(var))
}

#' @rdname se-deprecated
#' @param include,exclude Character vector of column names to always
#' include/exclude.
#' @export
select_vars_ <- function(vars, args, include = chr(), exclude = chr()) {
args <- compat_lazy_dots(args, caller_env())
select_vars(vars, !!! args, include = include, exclude = exclude)
}
#' @export
#' @rdname se-deprecated
rename_vars_ <- function(vars, args) {
args <- compat_lazy_dots(args, caller_env())
rename_vars(vars, !!! args)
}
143 changes: 0 additions & 143 deletions R/select-utils.R

This file was deleted.

Loading

0 comments on commit 4a07553

Please sign in to comment.