Helper to handle different ways we might choose columns
selectcreator.Rd
Tidyselect has a robust way of selecting columns, but we often need to do
that selection indirectly- ie pass the selecting in as an argument to an
outer function. There are a number of ways to do this, but this is reasonably
robust and general, relying on using tidyselect
itself. Allows passing
character vectors, bare names, or tidyselect syntax, provided this function
is called at the right place in the call stack
Arguments
- selectvals
the selection of columns. Can be character, bare names, or
tidyselect
syntax, e.g.tidyselect::starts_with()
. Iftidyselect
, it can include objects, but they need to be!!
. For example, ifprefix = 'ABC'
, to select columns starting with that prefix, should callselectvals = tidyselect::starts_with(!!prefix)
- data
a tibble or dataframe to find the columns
- failmissing
logical, default
TRUE
: fail if the requested grouping or aggregation columns not exist. IfFALSE
, proceed with those that do exist and silently drop those that don't
Value
a character vector of column names. The intention is to use them in
dplyr::group_by
or select
with dplyr::select(dplyr::across({{output}}))
. The underlying
eval_select
returns a named integer vector giving column indices, but we
return only the names because in use the indices may not be stable
throughout the calling function(s)