select_nse | R Documentation |
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).
select_nse(.data, ...)
.data |
data frame or tbl to select columns from. |
... |
unevaluated symbols to use as column names. |
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 } )
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.