Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

vars_pull

Select variable


Description

This function powers dplyr::pull() and various functions of the tidyr package. It is similar to vars_select() but returns only one column name and has slightly different semantics: it allows negative numbers to select columns from the end.

Usage

vars_pull(vars, var = -1)

Arguments

vars

A character vector of existing column names.

var

A variable specified as:

  • a literal variable name

  • a positive integer, giving the position counting from the left

  • a negative integer, giving the position counting from the right.

The default returns the last column (on the assumption that's the column you've created most recently).

This argument is taken by expression and supports quasiquotation (you can unquote column names and column locations).

Value

The selected column name as an unnamed string.

See Also

Examples

# It takes its argument by expression:
vars_pull(letters, c)

# Negative numbers select from the end:
vars_pull(letters, -3)

# You can unquote variables:
var <- 10
vars_pull(letters, !! var)

tidyselect

Select from a Set of Strings

v1.1.1
MIT + file LICENSE
Authors
Lionel Henry [aut, cre], Hadley Wickham [aut], RStudio [cph]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.