select_nse: Select columns non-standard (code capturing) interface.

View source: R/select_nse.R

select_nseR Documentation

Select columns non-standard (code capturing) interface.

Description

Select column that are exactly the names captured unevaluated from .... This is to provide a simple interface that reliably uses non-standard captured names (and not consequences of further evaluation). Please see https://win-vector.com/2018/09/23/a-subtle-flaw-in-some-popular-r-nse-interfaces/ for some discussion. Also accepts -name notation, but not integers or functions of columns. Does not look at argument names (so can not be used to rename columns).

Usage

select_nse(.data, ...)

Arguments

.data

data frame or tbl to select columns from.

...

unevaluated symbols to use as column names.

Examples


y <- "x"

# returns y-column
dplyr::select(data.frame(x = 1, y = 2), y)

# returns x-column (very confusing!)
dplyr::select(data.frame(x = 1), y)

# returns y-column
select_nse(data.frame(x = 1, y = 2), y)

# deletes wrong column!
dplyr::select(data.frame(x = 1, z = 3), -y)

# throws when y is not the name of a column (good)
tryCatch(
  select_nse(data.frame(x = 1), y),
  error = function(e) { e }
)

#' # throws when y is not the name of a column (good)
tryCatch(
  select_nse(data.frame(x = 1, z = 3), -y),
  error = function(e) { e }
)


WinVector/seplyr documentation built on Aug. 26, 2022, 12:01 p.m.