Skip to content

Error informatively when xobs_only() arguments are named or unknown - #112

Merged
joethorley merged 1 commit into
mainfrom
fix-111-xobs-only-names
Sep 8, 2026
Merged

joethorley merged 1 commit into
mainfrom
fix-111-xobs-only-names

Conversation

@joethorley

Copy link
Copy Markdown
Member

Closes #111.

A named argument inside xobs_only() failed with an internal stopifnot() from xcast() and, when it was the only argument, a dplyr cross-join deprecation warning attributed to newdata:

d <- tibble::tibble(a = 1:5 + 0.5, b = factor(letters[1:5]))
xnew_data(d, xobs_only(z = b))
#> Error in xcast(out, .data = .data):
#>   all(names(values) %in% names(.data)) is not TRUE

Approach

Names are rejected rather than applied.
xobs_only() preserves the combinations observed in .data, and a new column has no observed combinations, so a rename has nothing well defined to join on for a bare vector such as z = new_seq(b).
Naming the whole call, xnew_data(d, z = xobs_only(b)), continues to create a new column as #102 documents.

  • xobs_only() errors when any argument is named, naming the offending arguments.
  • semi_crossing() errors when a resulting column is not in .data, which also covers an unnamed bare vector, instead of falling through to an empty by and a cross join.
  • The ... documentation states that arguments must be unnamed variables in .data.
xnew_data(d, xobs_only(z = b))
#> Error: `xobs_only()` arguments must not be named ('z') as observed combinations must refer to columns of `.data`.
xnew_data(d, xobs_only(new_seq(b, .length_out = 2)))
#> Error: `xobs_only()` arguments must refer to columns of `.data` (unrecognised: 'new_seq(b, .length_out = 2)').

Checks

  • R CMD check: 0 errors, 0 warnings, 0 notes.
  • New test-xobs-only.R covers the observed-combination behaviour and snapshots the four error cases.

🤖 Generated with Claude Code

A named argument inside xobs_only() failed with an internal stopifnot
from xcast() and a dplyr cross-join deprecation warning. Names are now
rejected up front, since a new column has no observed combinations to
preserve, and semi_crossing() errors when an argument does not refer
to a column of .data instead of falling through to an empty join.

Closes #111.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@joethorley
joethorley merged commit e6bc906 into main Sep 8, 2026
11 checks passed
@joethorley
joethorley deleted the fix-111-xobs-only-names branch September 8, 2026 19:50
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.

xobs_only() does not handle named arguments

1 participant