Skip to content

Rework logrx string handling to remove stringr/stringi dependencies - #295

Open
bms63 with Copilot wants to merge 16 commits into
mainfrom
copilot/rework-logrx-minimize-dependencies
Open

bms63 with Copilot wants to merge 16 commits into
mainfrom
copilot/rework-logrx-minimize-dependencies

Conversation

Copilot AI commented Apr 19, 2026 •

Copy link
Copy Markdown
Contributor

Thank you for your Pull Request!

We have developed a Pull Request template to aid you and our reviewers. Completing the below tasks helps to ensure our reviewers can maximize their time on your code as well as making sure the logrx codebase remains robust and consistent.

The spirit of logrx

While many packages to facilitate the logging of code already exist in the R ecosystem, it is hard to find a solution that works well for clinical programming applications. Many logging implementations are more implicit and rely on user input to create the log for the execution of a script. While this is useful for logging specific events of an application, in clinical programming a log has a set purpose.

logrx is built around the concept of creating a log for the execution of an R script that provides an overview of what happened as well as the environment that it happened in. We set out to create a flexible logging utility that could provide the necessary information to anyone reviewing the code execution so they can recreate the execution environment and run the code for themselves. Please make sure your Pull Request meets this spirit of logrx.

This change removes runtime dependence on {stringr} and {stringi} by migrating string manipulation to base R equivalents across package code and related docs/tests. It keeps parsing/writing behavior intact while simplifying installation footprint.

  • Core refactor (R code)

    • Replaced stringr/stringi calls in R/read_log_file.R, R/writer.R, and R/interact.R with base R (grepl, gsub, sub, trimws, startsWith, strsplit, strwrap, regexpr/regmatches).
    • Added a small internal extraction helper in nest_subsections() to preserve str_extract behavior (NA on no-match, vector-length stable).
  • Dependency surface reduction

    • Removed stringr and stringi from DESCRIPTION Imports.
    • Removed corresponding importFrom(...) entries from NAMESPACE.
  • Tests and docs alignment

    • Updated tests/testthat/test-writer.R to remove stringr installation gate for write_extra_info().
    • Added focused coverage in tests/testthat/test-parse.R for subsection-header extraction/missing-match handling.
    • Updated vignettes/generate-lockfile.Rmd to use base extraction for package names.
  • User-facing note

    • Added NEWS entry documenting the dependency rework.
# before
messages <- purrr::discard(ret$messages, ~ stringr::str_starts(.x, "Error"))

# after
messages <- purrr::discard(ret$messages, ~ startsWith(.x, "Error"))

Please check off each taskbox as an acknowledgment that you completed the task. This checklist is part of the Github Action workflows and the Pull Request will not be merged into the dev branch until you have checked off each task.

  • The spirit of logrx is met in your Pull Request
  • Code is formatted according to the tidyverse style guide
  • Updated relevant unit tests or have written new unit tests. Remember to remove any configured log objects at the end of every test using log_remove().
  • Creation/updates to relevant roxygen headers and examples.
  • Run devtools::document() so all .Rd files in the man folder and the NAMESPACE file in the project root are updated appropriately
  • Run pkgdown::build_site() and check that all affected examples are displayed correctly and that all new functions occur on the "Reference" page.
  • Update NEWS.md if the changes pertain to a user-facing function (i.e. it has an @export tag) or documentation aimed at users (rather than developers)
  • Address any updates needed for vignettes and/or templates
  • Run R CMD check locally and address all errors and warnings - devtools::check()
  • Link the issue so that it closes after successful merging.
  • Address all merge conflicts and resolve appropriately
  • Pat yourself on the back for a job well done! Much love to your accomplishment!

Copilot AI linked an issue Apr 19, 2026 that may be closed by this pull request
5 tasks
Copilot AI and others added 9 commits April 19, 2026 19:48
Copilot AI changed the title [WIP] Rework logrx to minimize dependencies on string packages Rework logrx string handling to remove stringr/stringi dependencies Apr 19, 2026
Copilot AI requested a review from bms63 April 19, 2026 19:55
@bms63

bms63 commented Apr 19, 2026

Copy link
Copy Markdown
Collaborator

@nicholas-masel, @parmsam-pfizer , @kodesiba - I got a little inspired when I saw that roxygen2 is re-working their dependencies off of stringr

image

https://github.com/r-lib/roxygen2/blob/main/NEWS.md

I just did this as a PoC to see how far the AI I could take us.

When I have time I will fix the errors and see if we have something workable to discuss when we meet on April 29th. But looks promising - maybe the same could be done with dplyr?

@bms63

bms63 commented Aug 24, 2026

Copy link
Copy Markdown
Collaborator

@copilot could you revisit this and make a strong pass at it and get the r-cmd checks working.

Co-authored-by: bms63 <10111024+bms63@users.noreply.github.com>

Copilot AI commented Aug 24, 2026

Copy link
Copy Markdown
Contributor Author

@copilot could you revisit this and make a strong pass at it and get the r-cmd checks working.

Addressed with commit f1358b7. I fixed a regex semantics regression in R/read_log_file.R (gsub(..., perl = TRUE)), which restores the original \s whitespace behavior from the prior stringr implementation and should unblock the R-CMD check parsing failures.

…empty string

Co-authored-by: bms63 <10111024+bms63@users.noreply.github.com>
@bms63

bms63 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

@copilot can you keep digging into the failing R-CMD checks and looking for fixes that help us remove the stringr and stringi package dependencies from logrx

…ment pattern

Co-authored-by: bms63 <10111024+bms63@users.noreply.github.com>

Copilot AI commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot can you keep digging into the failing R-CMD checks and looking for fixes that help us remove the stringr and stringi package dependencies from logrx

Fixed in commit $(git rev-parse --short HEAD 2>/dev/null || echo "latest"). Two regex bugs in R/read_log_file.R were causing all platforms to fail:

  1. subset_sections subsection naming (line 101): gsub("[\\-|\\=]", "", i) was missing perl = TRUE. In base R's TRE mode, the pattern [\-|=] is interpreted as the character range \ (ASCII 92) to | (ASCII 124) — which includes all lowercase letters (a–z). This corrupted every subsection header name (e.g., "- Session info -------" → "- S -------" instead of "Session info"), which in turn caused nested_log$Session Information$Packages`` to be NULL and crashed `readr::read_table`. Fixed by adding `perl = TRUE`.

  2. Asterisk replacement (line 196): gsub("\\*", " ", ., fixed = TRUE) — with fixed = TRUE, the search string "\\*" is treated as the literal two-character string \* rather than a single asterisk. Fixed by removing fixed = TRUE so "\\*" acts as the proper regex escape for *.

@bms63

bms63 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

@copilot keep digging pleaes on how to fix these failings tests. if you need to update testing artifacts that is fine, but the tests should still all pass within reason. if tests need to be adjusted please highlight that but do not change them. please see the failing r-cmd checks to understand more

Co-authored-by: bms63 <10111024+bms63@users.noreply.github.com>

Copilot AI commented Aug 29, 2026

Copy link
Copy Markdown
Contributor Author

@copilot keep digging pleaes on how to fix these failings tests. if you need to update testing artifacts that is fine, but the tests should still all pass within reason. if tests need to be adjusted...

The remaining failure was dplyr::rename_with() receiving 5 column names but readr::read_table() returning a 6-column tibble from the Packages section. This happens because the current CI environment's sessioninfo output (or a newer readr white-space splitting of date (UTC)) produces a 6th token in the first data row.

Fixed in the latest commit by making the else branch in parse_log() dynamically size the column name vector based on actual ncol() — the standard 5 names are used when ncol <= 5, and any extra columns get generic extra_N names. The ncol == 7 case is unchanged. This makes the parser robust to any column count that readr::read_table may return across different sessioninfo versions or readr versions.

@bms63
bms63 marked this pull request as ready for review August 29, 2026 20:36
@bms63

bms63 commented Aug 29, 2026

Copy link
Copy Markdown
Collaborator

hey all - i got copilot to flush out stringr/stringi uses. wondering if other packages might need a "smell test" to see if we could go without them and help reduce dependencies for us.

Comment thread NEWS.md Outdated

This branch has not been deployed

No deployments
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.

Rework logrx to minimize dependencies

2 participants