R Incorrect coding in the Rstudio console (but normal in the R GUI and ggplot2)

I am in Windows 8.1 (ru), and my R console will not understand Russian characters and will produce something like this (both in the console and when I run the R file)

> x <- "" > print(x) [1] "ÏðèÒΓ₯Γ²" 

I know this can happen if you save CP1251 as CP1252. I configured all the R parameters to UTF-8, and the source files to UTF-8, but that doesn't help. I also installed sysLocale in Russian as here , but received nothing. Some tips from RStudio faq didn't help either. The strange thing, however, is that ggplot2 works absolutely fine

 dt <- as.data.frame(cbind(x = c("", ""), y = c(3, 5))) ggplot(dt, aes(x=x, y=y))+geom_bar() + xlab("") 

This is my sessionInfo ()

 R version 3.0.2 (2013-09-25) Platform: x86_64-w64-mingw32/x64 (64-bit) locale: [1] LC_COLLATE=Russian_Russia.1251 LC_CTYPE=Russian_Russia.1251 LC_MONETARY=Russian_Russia.1251 LC_NUMERIC=C [5] LC_TIME=Russian_Russia.1251 attached base packages: [1] stats graphics grDevices utils datasets methods base 

I am using the latest version of RStudio, but the dev version will not help either

UPDATE

 > Encoding(x) [1] "unknown" > getOption("encoding") [1] "native.enc" 

If I use RGUI, after Sys.setlocale("LC_ALL", "Russian") it will allow

 > print(x) [1] "" 

I also checked in the Russian version of Windows - Rstudio is working fine

+6
source share
2 answers
 Sys.setlocale("LC_ALL", "Russian") 

Not working for me.

 Sys.setlocale("LC_CTYPE", "en_RU.UTF-8") 

Did the job! now utf files with cyrillic characters are displayed in the R / RStudio console. But this only works until R or RStudio reboots.

also works

 defaults write org.R-project.R force.LANG en_US.UTF-8 

in OS X Terminal solves all my problems with non-Latin characters forever.

+2
source
 Sys.setlocale("LC_ALL", "Russian_Russia.1252") 

fixed the problem in my case.

+1
source

Source: https://habr.com/ru/post/957810/


All Articles