Dedupe gsub helper and drop redundant relevel_taxonomic_status_preferred_order() - #293
Dedupe gsub helper and drop redundant relevel_taxonomic_status_preferred_order()#293ehwenk wants to merge 5 commits into
Conversation
standardise_names(), strip_names(), and strip_names_extra() each defined an identical local helper: f <- function(x, find, replace) gsub(find, replace, x, perl = TRUE) Promote it to a single internal helper in a new R/utils.R and drop the three local copies; call sites are unchanged since the shared helper keeps the name `f`. standardise_taxon_rank()'s local `f` (fixed = TRUE, not perl = TRUE) is left alone -- it isn't identical to the other three. The other two cleanups in #282 (the repeated slash-pattern predicate and the per-row fuzzy-match loops in match_taxa()) were already resolved by the #283 refactor (apply_match()/fuzzy_match_column()/is_indecision()), confirmed via `git log -- R/match_taxa.R` and the "match_taxa.R duplication" note in AGENTS.md -- no further change needed there. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
synonyms_for_accepted_names() re-defined a byte-identical copy of relevel_taxonomic_status_preferred_order(), already a top-level (and thus package-wide visible) function in update_taxonomy.R -- the duplicate's own comment even said "(function from update_taxonomy.R)". Delete the nested copy; the call site now resolves to the shared top-level function. Found while reviewing #282; not part of that issue's original scope but the same kind of exact-duplicate-helper cleanup. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
`f` at package scope is ungreppable from its ~60 call sites, and it was shadowed in the same file by `standardise_taxon_rank()`'s local `f` (`fixed = TRUE`, not `perl = TRUE`) — two different regex semantics behind one name, one visible and one not. Rename to `gsub_perl()` (shared, in utils.R) and `gsub_fixed()` (local). Also drops two blank lines left after the opening brace in strip_names.R. Verified: outputs of standardise_names(), strip_names(), strip_names_extra() and standardise_taxon_rank() are identical() to master over 33 adversarial names + 13 ranks; devtools::test() 180 pass, 0 fail; devtools::document() leaves man/ and NAMESPACE unchanged. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
|
Reviewed, and I've pushed one follow-up commit (17f405c) rather than leaving it as a request — details below. Both original changes check out; I verified them rather than taking the description's word for it. VerificationBoth changes are genuinely behaviour-preserving. I loaded worktrees at
The
What I pushed, and whyThe one thing I didn't want to merge as-is was the helper being named
So 17f405c renames them to Re-verified after the rename: same Two notes for the record: Happy for this to go in once CI is green on the new commit. |
#292 added `g()` (str_replace anchored to end-of-string) specifically to stop "sectio"->"section" and "forma"->"form" corrupting values that already contain those as a substring ("section" -> "sectionn", "informal" -> "informl") -- its own comment explains exactly this. But the last two pipeline steps still called the old unanchored `gsub_fixed()` instead of the new `g()`, so the bug it was meant to fix was still live. Switch those two calls to `g()`. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Summary
Fixes the remaining part of #282: promotes the identical
gsub-wrapper helper duplicated instandardise_names(),strip_names(), andstrip_names_extra()into a single shared helper. Also removes an unrelated exact-duplicate function found while reviewing the same area.What changed
Dedupe the
gsub-perl helper (Minor code cleanups: duplicated helpers and per-row fuzzy loops #282). All three functions defined an identical local helper. Promoted to a singlegsub_perl()in newR/utils.R.standardise_taxon_rank()'s local helper isfixed = TRUE, notperl = TRUE, so it stays local — renamedgsub_fixed()so the two regex semantics are told apart by name rather than by scope.Drop redundant nested
relevel_taxonomic_status_preferred_order().synonyms_for_accepted_names()re-defined a byte-identical copy of this function, which already exists at top level (and is thus package-wide visible) inupdate_taxonomy.R— the duplicate's own comment even said(function from update_taxonomy.R). Deleted the nested copy; the call site now resolves to the shared top-level function.Not in scope here
The other two cleanups originally listed in #282 — the repeated slash-pattern predicate and the per-row fuzzy-match loops in
match_taxa()— were already resolved by #283's refactor (apply_match()/fuzzy_match_column()/is_indecision()). No further change needed there.Verification
Behaviour-preserving: outputs of all four touched string functions are
identical()tomaster, and so issynonyms_for_accepted_names().devtools::test()— 180 passed, 0 failed.devtools::document()— noNAMESPACE/man/changes.Closes #282
🤖 Generated with Claude Code