What problem does it solve?
rlang-patterns helps you write correct and robust R functions that work with tidy evaluation, avoiding common pitfalls when mixing data-masking, non-standard evaluation, and programmatic column references.
Core Features & Use Cases
- Data-masking argument forwarding with
{{}}: build functions that accept column expressions naturally, like summarise(mean = mean({{ var }})).
- Safe injection and splicing: use
!! for injecting single expressions/values and !!! for injecting multiple arguments from lists (e.g., group_by(!!!syms(vars))).
- Explicit pronoun disambiguation with
.data / .env: reference columns and environment variables unambiguously in summarise/mutate and loops.
- Dynamic dots patterns via
list2(): capture ... flexibly, support splicing, and create injected names using "{name}" := value.
- Bridges between tidy selection and data-masking: convert strings/vars into tidy-select or data-mask behavior using
across(), all_of(), and symbol helpers.
- Error-prone patterns to avoid: steer away from unsafe
eval(parse(...)) and collision-prone get() approaches, favoring !!sym() and .data[[var]].
Quick Start
Use rlang metaprogramming patterns to create a tidy-eval friendly summarise function by injecting a column expression with {{}} and, when building from strings, injecting symbols with !!sym().