Conversation
Add r2f handler for rep.int used as an index inside x[...], fail fast outside indexing, and add regression tests.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: fe33d9b357
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| len_expr <- r2size(times_arg, scope) | ||
| if (is.null(len_expr) || is_scalar_na(len_expr)) { | ||
| len_expr <- NA_integer_ |
There was a problem hiding this comment.
Use times value for rep.int length, not its size
The length you derive for the replicated index uses r2size(times_arg), which returns the size of the times expression (usually 1 for a scalar), not its runtime value. In x[rep.int(2L, n)] where n is a scalar integer (e.g., 4), this sets the index vector dims to length 1, so the subscript is treated as scalar during drop/shape inference in [ and the output shape becomes incorrect. The generated Fortran array constructor will still produce length n, so the wrapper’s metadata can disagree with the actual result. Consider propagating the actual times expression (or an unknown length) instead of r2size(times_arg).
Useful? React with 👍 / 👎.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #95 +/- ##
=======================================
Coverage 92.78% 92.78%
=======================================
Files 27 27
Lines 5754 5754
=======================================
Hits 5339 5339
Misses 415 415 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Re: Here This is exercised by |
Summary
rep.int()when used as an index insidex[...](e.g.x[rep.int(1L, 5L)]) by lowering it to a Fortran integer vector constructor.rep.int()used as a general value constructor errors to avoid silent type/semantic changes.NULL) with user-facing errors (no internal slot-access failures).Tests
tests/testthat/test-rep-int.Rcovering supported forms (positional,times=, non-literaltimes) and failure modes (outside indexing,NULLargs).R -q -e 'devtools::test()'