#| child: "setup.Rmd" #| include: FALSE
Functions like starts_with()
, contains()
or matches()
are
selection helpers that only work in a selection context, e.g.
dplyr::select()
or the cols
argument of tidyr::pivot_longer()
.
Using a selection helper anywhere else results in an error:
starts_with("foo") mtcars[contains("foo")] subset(mtcars, select = matches("foo"))
If you see this error, you may have used a selection helper in the wrong place, possibly as the result of a typo (e.g. misplaced comma or wrong argument name). Alternatively, you may be deliberately trying to reduce duplication in your code by extracting out a selection into a variable:
my_vars <- c(name, species, ends_with("color"))
To make this work you'll need to do two things:
any_of()
or all_of()
instead of bare variable namesmy_vars <- function() { c(any_of(c("name", "species")), ends_with("color")) } dplyr::select(starwars, my_vars())
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.