fix: drop=FALSE to prevent crash when exactly 1 row is unique to one side - #63
Merged
Conversation
…side combine.matrices.by.rowname.intersect() and merge_numeric_df_by_rn() share the same bug: after computing which row names are unique to each side (diffz[[1]], diffz[[2]]), they do rowSums(matrix1[diffz[[1]], ]) with the default drop = TRUE. When exactly one row name is unique to a given side, single-row matrix/ data.frame indexing collapses to a plain vector, and rowSums() on a non-array throws: Error in rowSums(...) : 'x' must be an array of at least two dimensions This is a realistic, not-rare input shape (any two inputs that share all but one row name each), not just a contrived edge case. Added drop = FALSE to both subsetting operations in both functions (4 call sites total) -- the identical fix, applied identically, since both functions have the exact same root cause. Verified with 4-row inputs sharing 3 row names (exactly 1 unique row on each side): - combine.matrices.by.rowname.intersect(m1, m2) now completes and returns the correctly merged 3x4 matrix, instead of erroring. - merge_numeric_df_by_rn(df1, df2) (data.frame inputs) now completes and returns the correctly merged 5x2 data frame, instead of erroring. Both functions' normal multi-row-difference behavior is unaffected (drop = FALSE is a no-op when more than one row is selected). Also bumps Development/config.R/DESCRIPTION to 2.8.13 per repo convention.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cf7f9a203a
ℹ️ 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".
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.
What was the bug?
combine.matrices.by.rowname.intersect()andmerge_numeric_df_by_rn()share the same bug. After computing which row names are unique to each side (diffz[[1]],diffz[[2]]fromsymdiff()), both dorowSums(matrix1[diffz[[1]], ])(or the data.frame equivalent) with the defaultdrop = TRUE.What was the impact?
When exactly one row name is unique to a given side, single-row matrix/data.frame indexing collapses to a plain vector (R's default
drop = TRUEbehavior), androwSums()on a non-array throws:This isn't a contrived edge case — it's the ordinary shape of "two inputs that share all but one row name each," which is exactly the kind of input these row-merging functions are meant to handle.
The fix
Added
drop = FALSEto both subsetting operations in both functions (4 call sites total) — the identical fix for the identical root cause, applied identically.Testing
Before: both calls errored with
'x' must be an array of at least two dimensions.After: both complete successfully — the first returns the correctly merged 3x4 matrix, the second the correctly merged 5x2 data frame. Both functions' normal multi-row-difference behavior is unaffected (
drop = FALSEis a no-op when more than one row is selected).R CMD build+R CMD check: no new NOTEs/WARNINGs/ERRORs vs. the currentdevbranch (the one remaining ERROR, a missing@exportonpU(), is pre-existing and already tracked separately)..Rd/NAMESPACEchange needed (roxygen blocks unchanged).testthat/automated tests added, per repo convention.Generated by Claude Code