fix: use getRUser() for Windows user home instead of USERPROFILE#68
Merged
fix: use getRUser() for Windows user home instead of USERPROFILE#68
Conversation
On Windows, R resolves `~` to the Documents folder (via SHGetKnownFolderPath), not USERPROFILE. When the Documents folder is moved to a different drive, USERPROFILE and Documents diverge, causing R_LIBS_USER paths like `~/R/win-library` to resolve to the wrong location. Replace the USERPROFILE-based fallback with R's own `getRUser()` from R.dll, which follows R's search order: R_USER → HOME → SHGetKnownFolderPath(Documents) → HOMEDRIVE+HOMEPATH → cwd. This matches ark's (Positron) approach to the same problem. Closes #65 Co-Authored-By: Claude Opus 4.6 <[email protected]>
getRUser() returns paths in the system's ANSI code page (e.g. CP932/Shift-JIS on Japanese Windows). The previous code used to_string_lossy() which corrupts non-ASCII characters. Use decode_windows_native() (encoding_rs-based) to properly convert from the system code page to UTF-8. Also document getRUser()'s memory ownership: it returns a pointer to a static buffer in R.dll that does not need to be freed. Co-Authored-By: Claude Opus 4.6 <[email protected]>
Co-Authored-By: Claude Opus 4.6 <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes Windows home directory resolution for embedded R initialization by using R’s own getRUser() (which matches how R resolves ~) instead of relying on USERPROFILE, addressing cases where the user’s Documents folder has been relocated (issue #65).
Changes:
- Switch Windows
params.homeinitialization to usegetRUser()fromR.dll. - Decode non-UTF-8
getRUser()results using the existing Windows code page conversion helper. - Document the behavior change in
CHANGELOG.md.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| crates/arf-libr/src/sys.rs | Uses getRUser() to determine Windows home for R params and decodes native-encoded paths. |
| crates/arf-libr/src/functions.rs | Adds dynamic symbol loading + function pointer for getRUser in the RLibrary loader. |
| CHANGELOG.md | Notes the Windows fix for ~/R_LIBS_USER resolution (#65). |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Use *const c_char for getRUser() return type (immutable static buffer) - Downgrade log level from info to debug for paths containing usernames - Fix comment: describe getRUser as R's ~ home, not always Documents Co-Authored-By: Claude Opus 4.6 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
getRUser()from R.dll instead ofUSERPROFILEforparams.homeon Windows (same approach as ark)getRUser()using the existing code page conversionProblem
On Windows, R resolves
~to the Documents folder (viaSHGetKnownFolderPath), notUSERPROFILE. When a user moves their Documents folder to a different drive,USERPROFILEand Documents diverge, causingR_LIBS_USERpaths like~/R/win-libraryto resolve to a non-existent location and installed packages become invisible to.libPaths().Test plan
normalizePath("~")matches standard R~/R/win-libraryresolves correctly and packages appear in.libPaths()Closes #65
🤖 Generated with Claude Code