You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
savehistory() / loadhistory() mis-decode "~" paths on Windows R < 4.2 when the home directory is non-ASCII #19684
RStudio Edition : Desktop
RStudio Version : main (2026.12 development)
OS Version : Windows
R Version : < 4.2 (native encoding is the ANSI code page, not UTF-8)
Steps to reproduce the problem
On Windows, use an account whose R home directory (path.expand("~")) contains a non-ASCII character that the ANSI code page can represent, e.g. C:\Users\José\Documents.
Start RStudio with R 4.1 or earlier.
Run savehistory("~/test.Rhistory"), then file.exists("~/test.Rhistory").
Describe the problem in detail
Found by reading the code while reviewing #19683; not yet reproduced on Windows.
On Windows, RStudio replaces utils::savehistory() and utils::loadhistory() with .rs.savehistory() / .rs.loadhistory(), which call rs_saveHistory / rs_loadHistory (src/cpp/r/session/RSession.cpp). Both do:
Since #19640, asString() returns UTF-8. On Windows, R_ExpandFileName() expands ~ by prepending the home directory as getenv() returns it, in the native code page. So the result mixes a native-encoded home directory with a UTF-8 remainder, and FilePath then decodes the whole string as UTF-8. The history is written to (or read from) the wrong path, or the call fails.
Before #19640 the whole string was native, so any non-ASCII history path was mis-decoded. #19640 fixed the paths that don't start with ~. This is the leftover case.
R's own path.expand() handles this case: on Windows it expands UTF-8 input with R_ExpandFileNameUTF8() and marks the result.
Describe the behavior you expected
savehistory("~/test.Rhistory") writes the history to path.expand("~/test.Rhistory"), and loadhistory() reads it back from there.
Activity
test that the history wrappers expand '~'
expand ~ in savehistory() / loadhistory() paths with path.expand() (#…