Skip to content

Drop stringr dependency#1841

Open
hadley wants to merge 18 commits intomainfrom
drop-stringr
Open

Drop stringr dependency#1841
hadley wants to merge 18 commits intomainfrom
drop-stringr

Conversation

@hadley
Copy link
Copy Markdown
Member

@hadley hadley commented Mar 21, 2026

No description provided.

hadley and others added 18 commits March 20, 2026 16:33
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Uses `gsub()` for simple string replacements and adds a
`re_replace_all()` helper for function-based replacements used in
`package_url_parse()`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Note that `strsplit("", pattern)` returns `character(0)` unlike
stringr's `str_split()` which returns `""`, so `tag_words()` now
guards against empty input before splitting.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Uses `substring()` where vectorization over start/end is needed,
and `substr()` for scalar operations. The replacement form
`str_sub(x, s, e) <- val` is replaced with manual string
concatenation since `substr<-` doesn't change string length.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Uses `regmatches()` + `regexec()` for `str_match()` and
`regmatches()` + `gregexec()` for `str_match_all()`.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Removes `@import stringr` and stringr from DESCRIPTION Imports.
Updates tests to use `fixed = TRUE` argument instead of stringr's
`fixed()` wrapper.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hadley hadley requested a review from gaborcsardi March 23, 2026 16:03
@hadley
Copy link
Copy Markdown
Member Author

hadley commented Mar 23, 2026

I think this is worth doing? It removes stringr from the devtools dependency tree (pak::pkg_deps_explain("devtools", "stringr")) which makes it easier to install for some folks. But there is some chance we (claude + me) haven't correctly accounted for some different base R edge case, so I think there's a small risk of regression.

Copy link
Copy Markdown
Member

@gaborcsardi gaborcsardi left a comment

Choose a reason for hiding this comment

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

Left some minor comments and questions.

"(?<=[^\\]\\\\]|^)",
"\\[([^\\]\\[]+)\\]",
"(?:\\[([^\\]\\[]+)\\])?",
"(?=[^\\[{]|$)"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think we can keep the comments here, no? (?x) should be extended mode in PERL regexes, so the comments are allowed? Or we could keep them as R comments?

}

generic <- str_split(x$val, "::")[[1]]
generic <- str_split_half(x$val, "::")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This seems like an improvement, but nevertheless it is a change of behavior, no?

n <- str_count(x$raw, "\\s+")
if (n > 1) {
warn_roxy_tag(x, "must have only one argument, not {n}")
warn_roxy_tag(x, "must have only one argument, not {n + 1}")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this change needed? It seems to break a snapshot test.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It was a mistake that I discovered. I must've forgotten to update the snapshot.

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