Skip to content

with_pattern() takes its pattern and parameters as dynamic dots - #136

Merged
trevorld merged 1 commit into
mainfrom
with_pattern-splice
Nov 12, 2026
Merged

trevorld merged 1 commit into
mainfrom
with_pattern-splice

Conversation

@trevorld

Copy link
Copy Markdown
Owner

with_pattern() and as.patternGrob() now take their pattern parameters as rlang dynamic dots, so a list or data frame of them can be spliced in with !!! instead of building the call with do.call():

with_pattern(grob, !!!params, prefix = "")
  • pattern moves into with_pattern()'s dots ("stripe" by default). with_pattern() is new, and this means an unnamed !!!params can't be matched positionally to pattern. A data frame's pattern column splices along with the other parameters, e.g. a {ggpattern} layer's data with prefix = "", which keeps fill and pattern_fill apart. The generic is now with_pattern(x, ...), and the grid methods are (x, ..., group, layers, delay, leaves, legend, prefix). with_pattern(grob, "circle") is now an error with a hint to write pattern = "circle".
  • The names in the dots are checked in one place. A spliced method argument (group, layers, x, ...) is an error, because spliced values never reach formals. A name given twice is an error. A factor parameter is taken as its labels.
  • as.patternGrob() collects its dots once, so a spliced x/y/id still gets the boundary hint. It builds its patternGrob() call with rlang::inject(), so a spliced gp or vp still reaches the right argument.
  • patternGrob() / grid.pattern() / patternFill() keep plain dots. Their pattern, x, y, and id come before ..., so an unnamed !!! would be matched to one of them. do.call() or rlang::inject() still work there.
  • Requires rlang (>= 1.0.0). The package already relied on it through on_package_load(), try_fetch(), and the call argument of abort().

No NEWS entry yet.

🤖 Generated with Claude Code

…dots

`with_pattern()` and `as.patternGrob()` now collect their `...` with
`rlang::list2()`, so a list or data frame of pattern parameters can be
spliced in with `!!!` (e.g. `with_pattern(grob, !!!params, prefix = "")`)
instead of building the call with `do.call()`.

`with_pattern()` is new, so its `pattern` moves from a formal argument
into the dots (`"stripe"` by default). A spliced `!!!params` can then
never be matched positionally to `pattern`, and the `pattern` column of
a data frame splices along with the other parameters (e.g. a
`{ggpattern}` layer's data with `prefix = ""`, which tells `fill` from
`pattern_fill`). The generic is now `with_pattern(x, ...)`.

The names in `with_pattern()`'s dots are checked in one place,
`dots_pattern()`. Spliced values never reach a method's own arguments, so
a spliced `group`, `layers`, `x`, etc. is an error rather than silently
becoming a pattern parameter. A name given twice is an error, and a
factor (e.g. a data frame column) is taken as its labels. The polygon
method of `as.patternGrob()` takes `vp` from its dots, so a spliced `vp`
isn't passed twice.

`patternGrob()` / `grid.pattern()` / `patternFill()` keep plain dots:
their `pattern`, `x`, `y`, and `id` come before `...`, so an unnamed
`!!!` would be matched to one of them. `as.patternGrob()` builds its
`patternGrob()` call with `rlang::inject()`, so spliced `gp` / `vp`
still reach those arguments.

Requires rlang (>= 1.0.0), which the package already relied on
(`on_package_load()`, `try_fetch()`, the `call` argument of `abort()`).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trevorld
trevorld merged commit c8603e0 into main Nov 12, 2026
4 checks passed
@trevorld
trevorld deleted the with_pattern-splice branch November 12, 2026 05:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant