Skip to content

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.


  var = -1,
  error_call = caller_env(),
  error_arg = caller_arg(var)



A character vector of existing column names.


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).


The execution environment of a currently running function, e.g. caller_env(). The function will be mentioned in error messages as the source of the error. See the call argument of abort() for more information.


An argument name as a string. This argument will be mentioned in error messages as the input that is at the origin of a problem.


The selected column name as an unnamed string.


# It takes its argument by expression:
vars_pull(letters, c)
#> [1] "c"

# Negative numbers select from the end:
vars_pull(letters, -3)
#> [1] "x"

# You can unquote variables:
var <- 10
vars_pull(letters, !!var)
#> [1] "j"