Repository navigation
Fix R startup on Windows when R_HOME or the user home has non-ASCII characters - #1453
Conversation
Merges into #1453 That PR isn't quite right because we can't trust `getRUser()` to return UTF-8. It's a complicated story with these two functions, `get_R_HOME()` and `getRUser()`, but the gist is: - `get_R_HOME()` is safe and returns UTF-8 in all paths it can take because we set UTF-8 in the manifest - `getRUser()` is _nearly_ safe, but the path that returns the `Documents` directory was sadly broken in R up until [this past month](wch/r-source@e1e4c5d) and wasn't guaranteed to return UTF-8. This is a very common case for this function. For this reason RStudio uses `get_R_HOME()` but has a custom replacement for `getRUser()` that fixes the UTF-8 issue. We now replicate the same idea. Lots more documentation inline in the comments in the code itself
Much harder to test a non-ascii `Directory` folder on CI
|
Highly related PR is rstudio/rstudio#11726 In particular with
|
|
After a bit of work I can confirm this is working on a windows machine. It's hard to add integration tests for changing the Pre patch,
|




Addresses posit-dev/positron#12303.
On Windows, ark now starts when the path to R contains non-ASCII characters. Before this change, ark exited with code 10 right after it loaded
R.dll, and the kernel log showed no error. The user in the issue hadøin their user name, so bothR_HOMEandR_USERcontained it.The cause was in
setup_r(). ark gotR_HOMEfromget_R_HOME()and the user home fromgetRUser()as bytes in the native encoding. Then ark converted these bytes to UTF-8 and gave the result back to R inRstart. The conversion used R'slocaleCP, but R giveslocaleCPa value only when it initializes its locale, later in startup. Before that,localeCPhas its compiled-in default of 1252. Our application manifest makes the process code page UTF-8, so the bytes were already UTF-8. As a result, ark decodedø(C3 B8) as CP1252 and gave R the path...StrømHals..., which does not exist.R_SetParams()writes this path to theR_HOMEandR_USERenvironment variables. Thenreadconsolecfg()tries to find$R_USER/Rconsoleand$R_HOME/etc/Rconsole. It finds neither file so it callsexit(10)(seesrc/gnuwin32/rui.cin R) and the Rust side didn't panic or log an error.Changes
get_r_home()andget_user_home()now return aCStringcopy of the bytes from R, with no conversion. R gets back the same bytes that it gave. A comment here explains why we don't want to do a conversion.system_to_utf8(), because no code uses it now.console_to_utf8()still useslocaleCP, but it runs only after R initializes its locale.Testing
C:\Users\Strøm\R\R-4.5.1.trace. TheR_HOME:line in the kernel log shows the correct path.Positron Release Notes
New Features
Bug Fixes