Repository navigation
with_pattern() takes its pattern and parameters as dynamic dots - #136
Merged
Merged
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
with_pattern()andas.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 withdo.call():patternmoves intowith_pattern()'s dots ("stripe"by default).with_pattern()is new, and this means an unnamed!!!paramscan't be matched positionally topattern. A data frame'spatterncolumn splices along with the other parameters, e.g. a{ggpattern}layer's data withprefix = "", which keepsfillandpattern_fillapart. The generic is nowwith_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 writepattern = "circle".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 splicedx/y/idstill gets the boundary hint. It builds itspatternGrob()call withrlang::inject(), so a splicedgporvpstill reaches the right argument.patternGrob()/grid.pattern()/patternFill()keep plain dots. Theirpattern,x,y, andidcome before..., so an unnamed!!!would be matched to one of them.do.call()orrlang::inject()still work there.on_package_load(),try_fetch(), and thecallargument ofabort().No NEWS entry yet.
🤖 Generated with Claude Code