Skip to content

fix: drop=FALSE to prevent crash when exactly 1 row is unique to one side - #63

Merged
vertesy merged 1 commit into
devfrom
fix/drop-false-single-row-crash
Aug 30, 2026
Merged

fix: drop=FALSE to prevent crash when exactly 1 row is unique to one side#63
vertesy merged 1 commit into
devfrom
fix/drop-false-single-row-crash

Conversation

@vertesy

@vertesy vertesy commented Aug 30, 2026

Copy link
Copy Markdown
Owner

What was the bug?

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]] from symdiff()), both do rowSums(matrix1[diffz[[1]], ]) (or the data.frame equivalent) with the default drop = 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 = TRUE behavior), and rowSums() on a non-array throws:

Error in rowSums(...) : 'x' must be an array of at least two dimensions

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 = FALSE to both subsetting operations in both functions (4 call sites total) — the identical fix for the identical root cause, applied identically.

Testing

# combine.matrices.by.rowname.intersect: 4 rows each, sharing 3, 1 unique per side
m1 <- matrix(1:8, nrow=4, dimnames=list(c("a","b","c","d"), c("x","y")))
m2 <- matrix(9:16, nrow=4, dimnames=list(c("b","c","d","e"), c("x","y")))
combine.matrices.by.rowname.intersect(m1, m2)

# merge_numeric_df_by_rn: same row-name pattern, data.frame inputs
df1 <- data.frame(v1 = c(1,2,3,4), row.names = c("a","b","c","d"))
df2 <- data.frame(v2 = c(9,10,11,12), row.names = c("b","c","d","e"))
merge_numeric_df_by_rn(df1, df2)

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 = FALSE is a no-op when more than one row is selected).

  • R CMD build + R CMD check: no new NOTEs/WARNINGs/ERRORs vs. the current dev branch (the one remaining ERROR, a missing @export on pU(), is pre-existing and already tracked separately).
  • No .Rd/NAMESPACE change needed (roxygen blocks unchanged).
  • No testthat/automated tests added, per repo convention.

Generated by Claude Code

…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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread Development/config.R
@vertesy
vertesy merged commit 40a5a59 into dev Aug 30, 2026
@vertesy
vertesy deleted the fix/drop-false-single-row-crash branch August 30, 2026 16:03
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.

2 participants