Skip to content

fix: inline FirstCol2RowNames() logic to remove undeclared dependency - #45

Merged
vertesy merged 3 commits into
devfrom
fix/firstcol2rownames-undeclared-dependency
Aug 28, 2026
Merged

fix: inline FirstCol2RowNames() logic to remove undeclared dependency#45
vertesy merged 3 commits into
devfrom
fix/firstcol2rownames-undeclared-dependency

Conversation

@vertesy

@vertesy vertesy commented Aug 28, 2026

Copy link
Copy Markdown
Owner

What was the bug?

merge_ls_of_named_vec_as_df_cols() (an exported function) ends with return(FirstCol2RowNames(COMBINED)). FirstCol2RowNames is defined in the ReadWriter package. CodeAndRoll2's DESCRIPTION only declares Depends: StringendoReadWriter is not a dependency anywhere (not Depends, not Imports).

Why did it happen?

At this point in the function, COMBINED is a plain data frame produced by repeatedly merge()-ing stack()-ed named vectors on their shared key column "ind" — so its first column holds the union of all the input vectors' names, and the rest are the merged value columns. FirstCol2RowNames() is presumably a ReadWriter convenience for "take the first column's values and use them as row names," which is a well-defined, unambiguous operation — but calling it here silently assumed ReadWriter would be available.

What was the impact of the old (wrong) behavior?

Calling merge_ls_of_named_vec_as_df_cols() — including with no arguments at all, since the function has full default values for every parameter — threw:

Error in FirstCol2RowNames(COMBINED) : could not find function "FirstCol2RowNames"

for any user who did not separately have ReadWriter loaded.

The fix

Inlined the "move first column's values into row names, then drop that column" logic directly:

rownames(COMBINED) <- as.character(COMBINED[[1]])
COMBINED[[1]] <- NULL
return(COMBINED)

instead of adding ReadWriter as a new dependency. CodeAndRoll2 is the most upstream, foundational @vertesy package (per its own README.md and AGENTS.md) and ReadWriter itself likely depends on it — declaring ReadWriter as an Import here would risk a circular package dependency. Inlining sidesteps that entirely and needs no external call. Happy to reconsider if the repo owner would rather declare the dependency instead.

Testing

merge_ls_of_named_vec_as_df_cols()  # uses the function's own default arguments

Before: Error in FirstCol2RowNames(COMBINED) : could not find function "FirstCol2RowNames".
After: returns the expected merged data frame —

  vec1 vec2 vec3 vec4
A    1  NaN    6  NaN
B    2    4  NaN    9
C    3  NaN    7   10
D  NaN    5    8   11
E  NaN  NaN  NaN   12

with rownames(res) correctly "A" "B" "C" "D" "E".

  • R CMD build + R CMD check: the "no visible global function definition for 'FirstCol2RowNames'" NOTE is gone; no new NOTEs/WARNINGs/ERRORs introduced (remaining output is pre-existing and unrelated — the other undeclared-dependency crash tracked in a separate PR, and long-standing missing base-package importFrom entries).
  • No .Rd/NAMESPACE change needed.
  • No testthat/automated tests added, per repo convention.

Generated by Claude Code

merge_ls_of_named_vec_as_df_cols() called bare FirstCol2RowNames(),
which is defined in the ReadWriter package. ReadWriter is not
declared anywhere in DESCRIPTION (Depends: Stringendo only), so any
call to this exported function threw
"could not find function 'FirstCol2RowNames'" unless the caller
happened to have ReadWriter separately loaded.

Fixed by inlining the (small, unambiguous) "move the first column's
values into row names, then drop that column" logic directly, rather
than declaring ReadWriter as a new dependency. CodeAndRoll2 is the
most upstream, foundational @vertesy package (per its own README and
AGENTS.md), and ReadWriter itself likely depends on it -- adding
ReadWriter as an Import here would risk a circular package
dependency. Inlining avoids that risk entirely.

Verified against the function's own default arguments:
merge_ls_of_named_vec_as_df_cols() now returns the expected merged
data frame with correct row names instead of erroring.

@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: 74d973ab42

ℹ️ 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 R/CodeAndRoll2.R
vertesy pushed a commit that referenced this pull request Aug 28, 2026
Per repo convention (AGENTS.md: bump Development/config.R by 0.0.1 for
a substantial code change) and reviewer feedback, so this fix is
distinguishable by version from the broken 2.8.1 release.

Note: this PR and its siblings in the same batch (#45, #46, #47, #48,
#49) each independently bump from the same 2.8.1 base to keep them
mergeable in any order; whichever merges first "claims" 2.8.2, and
the others may need a trivial one-line renumber at merge time
depending on actual merge order.
Per repo convention (AGENTS.md: bump Development/config.R by 0.0.1 for
a substantial code change) and reviewer feedback.

Note: this PR and its siblings in the same batch (#44, #46, #47, #48,
#49) each independently bump from the same 2.8.1 base with a distinct
target version to keep them mergeable in any order; a trivial one-line
renumber may be needed at merge time depending on actual merge order.
vertesy pushed a commit that referenced this pull request Aug 28, 2026
Per repo convention (AGENTS.md: bump Development/config.R by 0.0.1 for
a substantial code change) and reviewer feedback.

Note: this PR and its siblings in the same batch (#44, #45, #47, #48,
#49) each independently bump from the same 2.8.1 base with a distinct
target version to keep them mergeable in any order; a trivial one-line
renumber may be needed at merge time depending on actual merge order.
vertesy pushed a commit that referenced this pull request Aug 28, 2026
…ions

Follow-up to the seq_along/seq_len sweep in this PR: reorder.list()
and intermingle2lists() both initialized their accumulator as
list(NA) (a length-1 sentinel list). Previously, the 1:length(x)
version of their loop bound would crash on zero-length input before
this sentinel value could ever leak into the return value. Now that
the loop correctly does nothing for zero-length input
(seq_along(character(0)) / seq_len(0) both being empty), the
uninitialized sentinel list(NA) was returned as-is instead of the
correct empty list().

Fixed by initializing Lout <- list() in both functions -- list
elements are still assigned via Lout[[x]] <- ..., which auto-extends
a list on out-of-bounds assignment, so normal (non-empty) behavior is
unaffected.

Verified:
- intermingle2lists(list(a=1,b=2), list(c=3,d=4)) unchanged.
- intermingle2lists(list(), list()) now returns list() instead of
  list(NA).
- reorder.list(list(b=2,a=1,c=3)) unchanged.
- reorder.list(list(), namesOrdered = character(0)) now returns
  list() instead of list(NA).

Also bumps Development/config.R/DESCRIPTION to 2.8.5 per repo
convention and reviewer feedback (a distinct number from sibling
PRs #44/#45/#46/#48/#49 in this batch, all bumping from the same
2.8.1 base, so they stay mergeable in any order).
vertesy pushed a commit that referenced this pull request Aug 28, 2026
Reviewer feedback on the previous fix: CodeAndRoll2::zero.omit only
works if the package has been formally installed and its namespace
can be loaded. But README.md explicitly documents an alternative,
supported installation method -- sourcing R/CodeAndRoll2.R directly
(no install) -- and in that mode there is no "CodeAndRoll2" namespace
for :: to resolve against, so both functions would still crash with
zero.omit = TRUE for anyone using that method.

Replaced CodeAndRoll2::zero.omit with
get("zero.omit", mode = "function"). get()'s mode argument makes it
skip non-function bindings while searching up the enclosing scope
chain -- so it walks straight past the local logical zero.omit
argument (the actual shadowing problem) and finds the real function,
regardless of whether it's sitting in a loaded package's namespace or
in globalenv() from a direct source() call. Verified both scenarios:

- Package loaded via library(CodeAndRoll2): unchanged, works as
  before.
- File sourced directly (source("R/CodeAndRoll2.R"), package not
  installed/attached): as.list.df.by.col(dtf, zero.omit = TRUE) now
  also works, where CodeAndRoll2::zero.omit would have failed with
  "could not find function" (no such namespace loaded).

Also bumps Development/config.R/DESCRIPTION to 2.8.6 per repo
convention and reviewer feedback (a distinct number from sibling
PRs #44/#45/#46/#47/#49 in this batch, all bumping from the same
2.8.1 base, so they stay mergeable in any order).
vertesy pushed a commit that referenced this pull request Aug 28, 2026
Per repo convention (AGENTS.md: bump Development/config.R by 0.0.1 for
a substantial code change) -- applying proactively, matching the same
reviewer feedback already given on sibling PRs #44/#45/#46/#47/#48.

Note: this PR and its siblings in the same batch each independently
bump from the same 2.8.1 base with a distinct target version to keep
them mergeable in any order; a trivial one-line renumber may be
needed at merge time depending on actual merge order.

@vertesy vertesy left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ok

@vertesy

vertesy commented Aug 28, 2026

Copy link
Copy Markdown
Owner Author

@copilot resolve the merge conflicts in this pull request.

…undeclared-dependency

# Conflicts:
#	DESCRIPTION
#	Development/config.R

Co-authored-by: vertesy <5101911+vertesy@users.noreply.github.com>
@vertesy
vertesy merged commit 4eaccd6 into dev Aug 28, 2026
@vertesy
vertesy deleted the fix/firstcol2rownames-undeclared-dependency branch August 28, 2026 14:52
Copilot stopped work on behalf of vertesy due to an error August 28, 2026 14:52
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.

3 participants