RStudio can't deal with file names with unicode characters

Viewed 442

I've suddenly started having a problem in RStudio when I've got file/folder names that contain unicode characters. I've been running the exact same code for months, but it stopped working this morning.

For example, when I run list.files() on a file path containing "Ø", it doesn't work. However, I can change my working directory to that folder and then run list.files():

# RUNNING IN RSTUDIO
list.files("S:/Spildevand/Lille ØU-sag")
#> character(0)


setwd("S:/Spildevand/Lille ØU-sag")
list.files()
#>  [1] "~$P WW analysis.docx"                                                         
#>  [2] "Anmeldelse til Compliance"                                                    
#>  [3] "Budgetter_2021.03.22.xlsx"
#>  etc

But it works fine if I run it from the R GUI:

# RUNNING IN R GUI
list.files("S:/Spildevand/Lille ØU-sag")
#>  [1] "~$P WW analysis.docx"                                                         
#>  [2] "Anmeldelse til Compliance"                                                    
#>  [3] "Budgetter_2021.03.22.xlsx"
#>  etc

Similarly, saving an RDS file containing a special character works in R GUI, but not RStudio:

x <- 1
saveRDS(x, "æ rstudio.RDS")  # or "æ rgui.RDS"

enter image description here

I don't understand why this has suddenly started happening, nor why it would matter whether or not I run it in RStudio. The session info is slightly different, RStudio has two extra bits: system code page: 65001 and tools_4.1.2. Don't know what they mean or whether they're relevant.

RStudio: 
--------
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252  LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    
system code page: 65001

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.1.2 tools_4.1.2   



R GUI:
------
R version 4.1.2 (2021-11-01)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19042)

Matrix products: default

locale:
[1] LC_COLLATE=English_United Kingdom.1252 
[2] LC_CTYPE=English_United Kingdom.1252   
[3] LC_MONETARY=English_United Kingdom.1252
[4] LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.1252    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

loaded via a namespace (and not attached):
[1] compiler_4.1.2
2 Answers

R and RStudio are known to have unicode trouble on windows. Quoting a reply on this (similar but not identical) issue:

In general, the unfortunate truth right now for R on Windows is that you should restrict yourself to the characters representable in your native locale.

Your locale is shown to be English_United Kingdom.1252 and you're trying to use file names with characters outside it. There's a good chance changing your locale to match the file names would help.
I don't have a windows 10 machine to verify, but the internets say it'd done via Settings>Time & Language>Region & language.

Related