Name columns from named non-symbol arguments in xnew_data() - #110
Merged
Merged
Conversation
`xnew_data()` only applied the argument name to the value for bare symbols, so a named non-symbol argument reached `tidyr::expand()` with its name intact. A bare factor vector was then expanded to all of its levels, discarding `.length_out` and `.obs_only`, and a one column data frame became a packed data frame column. `xnew_column()` now applies the name to the value for every named argument, dispatching on the value since its type is not knowable from the expression. A multi column data frame stays packed as before. Co-Authored-By: Claude Opus 5 (1M context) <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.
Closes #109.
Note
Stacked on #102, which this builds on directly.
Base is
fix-99-named-symbol-column; retarget tomainonce #102 merges.#102 applied the argument name to the value only for bare symbols.
Every other named argument reached
tidyr::expand()with its name intact, which gave twobugs:
The first is the idiom in
xnew_seq()'s own examples, so it was reachable from thedocumentation.
Approach
expand()sorts and deduplicates an argument's values whether it is a bare vector or adata frame, so that is not the distinction.
The one behaviour that differs is factors: a bare factor vector is expanded to all of its
levels, whereas a factor held in a data frame keeps only the values present.
That level expansion is what discarded
.length_outand.obs_only.xnew_column()therefore gives every named argument the treatment #102 gave named symbols:The dispatch is on the value rather than the expression because the type is not knowable
statically, so the helper is inlined into the quosure -- it is internal, and the quosure is
evaluated in the caller's environment where it would not otherwise be in scope.
The outer name is now dropped for every named argument rather than only for symbols, which
also removes the
map_lgl()scan of the quosures.Checks
R CMD check: 0 errors, 0 warnings, 0 notes.(
b = 8:10,z = "zed",a = new_value(a)) are unaffected because those values arealready sorted and unique.