fix: stop overriding R_LIBS_SITE and let R handle it#87
Conversation
Previously, when R_LIBS_SITE was unset, arf unconditionally set it to R_HOME/library. This is incorrect because R_HOME/library is always included as .Library regardless of R_LIBS_SITE. Per R's documented behavior (?base::libPaths), when R_LIBS_SITE is unset, R uses R_HOME/site-library if it exists. Some R distributions (e.g., Scoop on Windows) provide a site-library directory linked to a persisted location. Now arf only sets R_LIBS_SITE when R_HOME/site-library exists, matching base R's default initialization logic. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Extract set_r_libs_site_from_r_home() as a testable function and add two tests: - Sets R_LIBS_SITE to R_HOME/site-library when the directory exists - Leaves R_LIBS_SITE unset when site-library does not exist Co-Authored-By: Claude Opus 4.6 <[email protected]>
- Insert blank line to break the doc comment for set_r_path_vars_from_wrapper from set_r_libs_site_from_r_home - Reword SAFETY comment to be accurate for both production and test contexts Co-Authored-By: Claude Opus 4.6 <[email protected]>
…omments lint Relocate the function after set_r_path_vars_from_wrapper instead of before it, so it no longer splits an existing doc comment block. Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect handling of the R_LIBS_SITE environment variable during R initialization. Previously, arf set R_LIBS_SITE to R_HOME/library, which is incorrect because R always includes that directory as .Library. The fix aligns with R's default behavior by setting R_LIBS_SITE to R_HOME/site-library only when that directory exists.
Changes:
- Extracted
set_r_libs_site_from_r_home()helper function to setR_LIBS_SITEconditionally - Changed logic from checking
R_HOME/libraryto checkingR_HOME/site-library - Added two unit tests to verify the new behavior
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
R handles R_LIBS_SITE via Renviron (defaulting %S to R_HOME/site-library when unset) and .Library (R_HOME/library) is always included regardless. ark, radian, and sircon all delegate this to R without explicit setup. The original R_LIBS_SITE code was added as a workaround during JIT crash debugging (a3972e9), but the actual fix was the run_Rmainloop architecture change (12e3661) moments later. With proper R initialization in place, explicit R_LIBS_SITE setup is unnecessary. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Why this code existed in the first placeThe
The Comparison with other R embedding projects
All three rely on R's built-in initialization: |
R_LIBS_SITE and let R handle it
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
R_LIBS_SITEinitialization from arf's R startup sequenceR_LIBS_SITEviaRenviron(defaulting%StoR_HOME/site-librarywhen unset) and.Library(R_HOME/library) is always included regardlessCloses #86
Background
The
R_LIBS_SITEcode was originally added during a JIT crash debugging session (a3972e9, 2026-01-12, private branch). The crash message was "Fatal error: unable to initialize the JIT", and settingR_LIBS_SITEtoR_HOME/librarywas an attempt to ensure R could find thecompilerbase package. However, the actual fix turned out to be therun_Rmainlooparchitecture change (12e3661, private branch) just 7 minutes later. TheR_LIBS_SITEworkaround was left in place but was always redundant —.Libraryalready guaranteesR_HOME/libraryis on the search path.The incorrect value (
R_HOME/libraryinstead ofR_HOME/site-library) went unnoticed until #86 reported that Scoop-installed R on Windows has asite-librarysymlink that arf was ignoring.Test plan
.Libraryalways includesR_HOME/libraryandR_LIBS_SITEis handled by R'sRenviron/Rprofilechainsite-libraryis correctly discovered by R🤖 Generated with Claude Code