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
~ paths mis-decoded by RStudio's list.files(), browseURL(), and other R_ExpandFileName() callers on Windows R < 4.2 with a non-ASCII home directory #19724
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, set R_USER to a directory containing a non-ASCII character that the ANSI code page can represent (e.g. Crème), with a few files in it.
Start RStudio with R 4.1 or earlier.
Run list.files("~").
Describe the problem in detail
Found by @gtritchie while reviewing #19685; not yet reproduced on Windows.
This is the same encoding mismatch as #19684, in other callers. On Windows, R_ExpandFileName() expands ~ by prepending the home directory as getenv() returns it, in the native code page. These callers pass it a UTF-8 string, so the result mixes a native home directory with a UTF-8 remainder, and it is then decoded as UTF-8:
initializePaths() (src/cpp/session/modules/SessionFiles.cpp) runs Rf_translateCharUTF8(), then R_ExpandFileName(). RStudio's list.files() / list.dirs() / dir() replacements use it, and SessionPatches.R turns them on by default on Windows with R < 4.2. So list.files("~") names a directory that doesn't exist.
r::sexp::extract(SEXP, FilePath*) (src/cpp/r/RSexp.cpp) extracts the string as UTF-8, then calls r::util::expandFileName().
rs_browseURL() (src/cpp/r/session/RSession.cpp) calls r::util::expandFileName() on file paths with no URL scheme, e.g. browseURL("~/report.html").
r::util::expandFileName() (src/cpp/r/RUtil.cpp) is a thin wrapper around R_ExpandFileName(). Making it take and return UTF-8 (convert to native, expand, convert back) would fix the last two, and initializePaths() could call it instead of R_ExpandFileName(). #19685 fixed savehistory() / loadhistory() by expanding ~ with path.expand() in R; they could use the fixed helper as well.
The POSIX callbacks in RStdCallbacks.cpp aren't affected: they pass native strings to R_ExpandFileName(), and FilePath on POSIX uses the bytes as they are.
Describe the behavior you expected
list.files("~") lists the home directory's files, and ~ paths passed to the other callers name the home directory.
Activity
read the r version from the r dll when expanding ~ on windows
expand ~ to a utf-8 home directory on windows with r < 4.2 (#19899)