Skip to content

RStudio resets locale when call to View() #15008

Open

Description

@larssnip

System details

RStudio Edition : 2024.04.2 Build 764
RStudio Version : RStudio 2024.04.2+764 "Chocolate Cosmos" Release (e4392fc9ddc21961fd1d0efd47484b43f07a4177, 2024-06-05) for windows

Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) RStudio/2024.04.2+764 Chrome/120.0.6099.291 Electron/28.3.1 Safari/537.36, Quarto 1.4.555
OS Version : Windows 10 Enterprise
R Version : 4.4.1

Steps to reproduce the problem

`

Sys.getlocale()
[1] "C" # a useless locale
txt <- "æøå" # this fails now
txt
[1] "���"
Sys.setlocale(category = "LC_ALL", locale = "") # setting the proper locale
[1] "LC_COLLATE=Norwegian Bokmål_Norway.utf8;LC_CTYPE=Norwegian Bokmål_Norway.utf8;LC_MONETARY=Norwegian Bokmål_Norway.utf8;LC_NUMERIC=C;LC_TIME=Norwegian Bokmål_Norway.utf8"
Sys.getlocale()
[1] "LC_COLLATE=Norwegian Bokmål_Norway.utf8;LC_CTYPE=Norwegian Bokmål_Norway.utf8;LC_MONETARY=Norwegian Bokmål_Norway.utf8;LC_NUMERIC=C;LC_TIME=Norwegian Bokmål_Norway.utf8"
txt <- "æøå" # and now this works fine
txt
[1] "æøå"
View(mpg) # calls the Viewer in RStudio
Sys.getlocale()
[1] "C" # and we are back to the same useless locale again
txt <- "æøå"
txt
[1] "���"`

Describe the problem in detail

I am using a computer with norwegian locale, but RStudio does not seem to register this in the first place. When I run in the Console:
`

Sys.getlocale()
[1] "C"`

If I start R outside RStudio it looks like this:
`

Sys.getlocale()
[1] "LC_COLLATE=Norwegian Bokmål_Norway.utf8;LC_CTYPE=Norwegian Bokmål_Norway.utf8;LC_MONETARY=Norwegian Bokmål_Norway.utf8;LC_NUMERIC=C;LC_TIME=Norwegian Bokmål_Norway.utf8"`

This is correct, and letters like æøå are recognized. Next, I set the locale in RStudio:
`

Sys.setlocale(category = "LC_ALL", locale = "")
[1] "LC_COLLATE=Norwegian Bokmål_Norway.utf8;LC_CTYPE=Norwegian Bokmål_Norway.utf8;LC_MONETARY=Norwegian Bokmål_Norway.utf8;LC_NUMERIC=C;LC_TIME=Norwegian Bokmål_Norway.utf8"
Sys.getlocale()
[1] "LC_COLLATE=Norwegian Bokmål_Norway.utf8;LC_CTYPE=Norwegian Bokmål_Norway.utf8;LC_MONETARY=Norwegian Bokmål_Norway.utf8;LC_NUMERIC=C;LC_TIME=Norwegian Bokmål_Norway.utf8"`

Everything seems to work fine, but as soon as I make a call to View() (opens a data.frame for viewing) it is set back to the old and useless locale again!
`

View(mpg)
Sys.getlocale()
[1] "C"`

Also, adding the Sys.setlocale-statement to my .Rprofile has no effect at all, it is clearly being reset again after the execution of .Rprofile

Describe the behavior you expected

First, I expect RStudio to use the locale of my computer in the first place. This is clearly done in R outside RStudio.
Second, I would expect setting the locale in my .Rprofile would take effect and not be reset by RStudio.
Third, when I set the locale explicitly in a session, I do not expect it to change back to some useless locale each time I call View()

  • [x ] I have read the guide for submitting good bug reports.
  • [ x] I have installed the latest version of RStudio, and confirmed that the issue still persists.
  • If I am reporting an RStudio crash, I have included a diagnostics report.
  • [ x] I have done my best to include a minimal, self-contained set of instructions for consistently reproducing the issue.

Activity

  1. added
    new
    on Jul 26, 2024
  2. ronblum commented on Jul 26, 2024

    @ronblum
    Contributor

    @larssnip Thank you for raising the issue: I can confirm that

    1. The problem started when we switched over from the Qt to Electron framework: This works correctly in the Qt version of RStudio Desktop 2022.7.2.576, but the locale of "C" is returned in the Electron version.
    2. I can reproduce this in Norwegian (Bokmål). It works correctly in French (France).
  3. added
    locale
    and removed
    new
    on Jul 26, 2024
  4. kevinushey commented on Jul 30, 2024

    @kevinushey
    Collaborator

    For what it's worth, I was not able to reproduce with this code:

    Sys.setlocale(locale = "Norwegian Bokmål_Norway.utf8")
    mpg <- mtcars$mpg
    View(mpg)
    Sys.getlocale()
    

    so reproducing seems to require explicitly changing the system language to Norwegian?

  5. ronblum commented on Jul 30, 2024

    @ronblum
    Contributor

    @kevinushey Yes, that's what I had to do.

  6. larssnip commented on Aug 6, 2024

    @larssnip
    Author

    Yes, my computer uses a norwegian Windows, and I guess this code:

    Sys.setlocale(category = "LC_ALL", locale = "")

    will fetch the locale from windows and use this in R/RStudio. This works but, as explained above, only a short time before RStudio resets it. However, I have found that if I instead use:

    Sys.setlocale(category = "LC_ALL", locale = "NO_NB.utf8")

    it works and persists! This means I do not collect the locale from Windows, but specify it like this. This is NOT the same locale that I get from windows, but it works nice with the nordic letters. And it seems to persist, i.e. is not reset by RStudio. I now put this into my .Rprofile and the problems seems to be solved.

  7. ronblum commented on Aug 6, 2024

    @ronblum
    Contributor

    @larssnip That's great--I'm glad to hear that there's a workaround!

    It appears to be an issue with the special character in the name. I tried several other languages, including Norwegian (Nynorsk) and Arabic (Egypt), which work. However, French (Côte d’Ivoire) has the same bug as Norwegian (Bokmål).

    Side note: Almost all of the names have been anglicized, without special characters--for example, French not français--so I'm surprised to see a few that haven't been--e.g., Côte d’Ivoire not Ivory Coast.

  8. added this to the Later milestone on Aug 6, 2024
  9. modified the milestones: Later, Kousa Dogwood on Aug 6, 2024
  10. jthomasmock commented on Sep 27, 2024

    @jthomasmock
    Contributor

    Glad to hear about the workaround and details, we'll evaluate this alongside other locale and i18n issues in the future.

  11. oyvindbso commented on Nov 19, 2025

    @oyvindbso

    I finally found out what was the problem (the å in Bokmål) and found this post. This has bugged me for a looong time.

    It would be great if Rstudio could support it (even if Bokmål is a very minor language internationally). I was not able to reproduce the error in R gui so it is only a problem in Rstudio.
    My code has looked like this since it became a problem;
    some r code
    Sys.setlocale(category = "LC_ALL", locale = "")
    some r code
    Sys.setlocale(category = "LC_ALL", locale = "")
    some r code

    Of course if I had used the other version of Norwegian in the system settings (Nynorsk) there wouldn't have been a problem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    buglocale

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions