1

I have the following problem and haven't found a solution in the last 3h:

test=c("sähköpyörä")
print(test)

yields

"s\303\244hk\303\266py\303\266r\303\244"

However, I should stay "sähköpyörä".

Anyone has an idea how to handle the problem?

I'm running R Studio 1.1.447 on Mac OS X 10_15_3. Thanks!

MrFlick
  • 195,160
  • 17
  • 277
  • 295
Datenjongleur
  • 13
  • 1
  • 4

1 Answers1

1

You need to save the file with UTF-8 Encoding. I'm running R-Studio 1.2.5042 on Windows and can confirm that this works.

Open your script, goto File->Save with Encoding->UTF-8.

The next time you open your script, you must first open the file, then click

File->Reopen with Encoding->UTF-8

To Set this globally instead of every time you open the file, goto Tools->Global Options->Code->Saving->Set default text Encoding to UTF-8

freebird
  • 26
  • 7
  • Unfortunately doesn't work for me ;-( Could it be a Mac OS issue? I get the following error message when starting RStudio now: During startup - Warning messages: 1: Setting LC_CTYPE failed, using "C" 2: Setting LC_COLLATE failed, using "C" 3: Setting LC_TIME failed, using "C" 4: Setting LC_MESSAGES failed, using "C" 5: Setting LC_MONETARY failed, using "C" – Datenjongleur Apr 28 '20 at 21:58
  • 1
    Was all those errors at startup of RStudio? Or while trying to run or load the script? Was the only setting changed the text encoding? While were at it, I would suggest updating your R studio to the latest version via https://rstudio.com/products/rstudio/download/#download Oh, and make sure you Clean the Environment, press the "broom" in the Environment tab to "Clear objects from the workspace" – freebird Apr 28 '20 at 22:08
  • Upon more research, those error messages do appear to be the result of known problem with R Studio on mac. Try the commands listed here-> https://stackoverflow.com/questions/9689104/installing-r-on-mac-warning-messages-setting-lc-ctype-failed-using-c Open terminal and type in `defaults write org.R-project.R force.LANG en_US.UTF-8` and restart R-Studio – freebird Apr 28 '20 at 22:13
  • Thank you freebird! Updating R and RStudio and setting UTF-8 as default worked out in the end! – Datenjongleur Apr 29 '20 at 06:39