metaprogramming

Automate R metaprogramming workflows by defusing, building, and injecting code with rlang.

13|2|Updated Jan 13, 2026
One-click install
npx skills add https://github.com/jsperger/llm-r-skills --skill metaprogramming
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: metaprogramming
Source: https://github.com/jsperger/llm-r-skills/tree/main/skills/metaprogramming
Command: npx skills add https://github.com/jsperger/llm-r-skills --skill metaprogramming

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps developers write and manipulate R code at the level of expressions, enabling programmatic generation, transformation, and injection of code using rlang's defuse/inject patterns.

Core Features & Use Cases

  • Defuse and reassemble expressions with expr(), enquo(), and enquos() to inspect and modify code.
  • Build quosures and manage environments for correct evaluation across packages and data masks.
  • Inject transformed expressions back into data-masked calls with operators like !! and {{ for forwarding arguments.
  • Use cases include generating dynamic function calls in packages, creating meta-programming utilities, and teaching concepts of tidy evaluation.

Quick Start

Use the metaprogramming skill to understand how to defuse an expression, wrap it in a quosure, and inject it into a data-masked context.

Frequently Asked Questions about metaprogramming

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I defuse and inject expressions in R using rlang?

To defuse and inject expressions in R, use rlang primitives like `expr()`, `enquo()`, and `enquos()` to capture code, then inject them into data-masked calls using `!!` and `{{` operators. This approach enables programmatic generation and transformation of R code.

What is tidy evaluation and how do quosures manage environments in R?

Tidy evaluation is an R metaprogramming paradigm where quosures capture both an expression and its environment. Using rlang functions like `quo_get_expr` and `quo_get_env`, developers ensure correct evaluation across packages and data masks.

Can I generate dynamic function calls programmatically in R packages?

Yes, you can generate dynamic function calls in R packages by defusing arguments with `enquo()`, modifying the resulting expressions, and injecting them back into data-masked contexts. This allows programmatic code generation for library development.

Do I need a specific R version to use rlang defuse and inject patterns?

Yes, rlang defuse and inject patterns require R version 4.3 or higher and rlang version 1.1.3 or higher. These versions provide the necessary front-mended primitives for building and inspecting quosures.

Why does my injected expression fail to evaluate in a data mask?

Injected expressions fail when quosures are not properly built or environments are mismatched. Use `quo_get_env` to verify the captured environment and ensure you are using `!!` or `{{` operators correctly within data-masked calls for proper evaluation.

What is the best way to forward multiple arguments in R metaprogramming?

The best way to forward multiple arguments in R metaprogramming is using `enquos()` to defuse them into a list of quosures, then injecting them with the `!!!` operator. This pattern ensures correct environment tracking across data masks.