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

Description Usage Arguments Examples

View source: R/select_nse.R

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

1
select_nse(.data, ...)

Arguments

.data

data frame or tbl to select columns from.

...

unevaluated symbols to use as column names.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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 }
)

seplyr documentation built on Sept. 5, 2021, 5:12 p.m.