Skip to content

fix: use getRUser() for Windows user home instead of USERPROFILE#68

Merged
eitsupi merged 4 commits intomainfrom
fix/windows-user-home-getruserhome
Feb 7, 2026
Merged

fix: use getRUser() for Windows user home instead of USERPROFILE#68
eitsupi merged 4 commits intomainfrom
fix/windows-user-home-getruserhome

Conversation

@eitsupi
Copy link
Copy Markdown
Owner

@eitsupi eitsupi commented Feb 7, 2026

Summary

  • Use R's getRUser() from R.dll instead of USERPROFILE for params.home on Windows (same approach as ark)
  • Properly decode non-UTF-8 paths from getRUser() using the existing code page conversion

Problem

On Windows, R resolves ~ to the Documents folder (via SHGetKnownFolderPath), not USERPROFILE. When a user moves their Documents folder to a different drive, USERPROFILE and Documents diverge, causing R_LIBS_USER paths like ~/R/win-library to resolve to a non-existent location and installed packages become invisible to .libPaths().

Test plan

  • On Windows with Documents folder on the same drive: verify normalizePath("~") matches standard R
  • On Windows with Documents folder moved to a different drive: verify ~/R/win-library resolves correctly and packages appear in .libPaths()
  • On non-ASCII username Windows: verify path is correctly decoded

Closes #65

🤖 Generated with Claude Code

eitsupi and others added 3 commits February 7, 2026 08:18
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]>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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.home initialization to use getRUser() from R.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]>
@eitsupi eitsupi merged commit 5794e3c into main Feb 7, 2026
10 checks passed
@eitsupi eitsupi deleted the fix/windows-user-home-getruserhome branch February 7, 2026 08:34
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.

'R_LIBS_USER' is not recognized on Windows, so the installed package cannot be loaded

2 participants