Skip to content

Ensure packages referenced using :: notation are included in reproducibility table#314

Closed
kelliemac wants to merge 5 commits intodevelopfrom
add-packages-to-reproducibility-table
Closed

Ensure packages referenced using :: notation are included in reproducibility table#314
kelliemac wants to merge 5 commits intodevelopfrom
add-packages-to-reproducibility-table

Conversation

@kelliemac
Copy link
Contributor

@kelliemac kelliemac commented Nov 19, 2025

Description

Attempt to automatically include packages leveraged in main report Rmd file using :: notation in the reproducibility table at the end of a report.

These code changes were mostly done by CoPilot, but carefully reviewed for validity by Kellie.

Related Issues

#211

Checklist

  • This PR includes unit tests
  • This PR establishes a new function or updates parameters in an existing function
    • The roxygen skeleton for this function has been updated using devtools::document
  • I have updated NEWS.md to describe the proposed changes

@kelliemac kelliemac changed the title Add packages referenced using :: to reproducibility table Add packages referenced using :: notation to reproducibility table Nov 19, 2025
@codecov
Copy link

codecov bot commented Nov 21, 2025

Codecov Report

❌ Patch coverage is 70.00000% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 84.93%. Comparing base (81f6b30) to head (73a6cf3).
⚠️ Report is 27 commits behind head on develop.

Files with missing lines Patch % Lines
R/misc.R 70.00% 3 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff             @@
##           develop     #314      +/-   ##
===========================================
- Coverage    85.33%   84.93%   -0.40%     
===========================================
  Files            9        9              
  Lines          375      385      +10     
===========================================
+ Hits           320      327       +7     
- Misses          55       58       +3     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kelliemac kelliemac marked this pull request as ready for review December 4, 2025 01:29
@kelliemac kelliemac requested a review from slager December 4, 2025 01:29
@kelliemac
Copy link
Contributor Author

@slager do you have any thoughts on how to extend these unit tests so that the code coverage checks pass?

R/misc.R Outdated
#' @return Character vector of unique package names (may be length 0).
#' @export
#' @family utilities
detect_namespaces_in_file <- function(path){
Copy link
Contributor

Choose a reason for hiding this comment

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

This function could be deleted, and the other function could just be called with readLines(knitr::get_current_input()) as its argument.

# ensure packages referenced with :: are loaded before calling get_session_info()
pkgs_to_load <- detect_namespaces_in_file(knitr::current_input())
for (pkg in pkgs_to_load) {
if (any(installed.packages()[,1] == pkg)) suppressWarnings(library(pkg, character.only = TRUE))
Copy link
Contributor

@slager slager Dec 4, 2025

Choose a reason for hiding this comment

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

Here and in the other skeleton, I think this approach could use an adjustment (and/or discussion). Loading a package into the search path via library() can produce different behaviors than accessing a package's function using the :: syntax. So, in the attempt to document which packages were used, we'd in effect be creating a reproducibility table that shows a different R environment than what was used in the main script.

One possibility is converting this into a check that throws an error if not all packages called by :: are already loaded into the search path, and let get_session_info() do the rest of the work. This would force users to list their library calls up front, which is kind of a best practice anyway since it's nice to see up near the top what your script depends on. Alternatively, and this would probably be the most accurate, would be to try to parse loaded namespaces and attached namespaces and disambiguate those in the reproducibility table. This would give users more flexibility in how they choose to use library() and pkg::fun() calls.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that makes sense to me! I will make some adjustments.

@kelliemac kelliemac changed the title Add packages referenced using :: notation to reproducibility table Ensure packages referenced using :: notation are included in reproducibility table Dec 5, 2025
@kelliemac
Copy link
Contributor Author

per discussion today, @slager will start a fresh branch / PR with a different approach to list all namespaces and add a column to table indicating if attached or not

@slager
Copy link
Contributor

slager commented Dec 6, 2025

Implemented at FredHutch/VISCfunctions#132

@kelliemac
Copy link
Contributor Author

closing in light of FredHutch/VISCfunctions#132 (review) and #329

@kelliemac kelliemac closed this Dec 6, 2025
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