Jindra Lacko
Jindra Lacko

Reputation: 8749

Czech encoding in R

I have installed RStudio on a new computer, and has developed encoding issues. When I type accented text in console (no file writing or reading involved, just plain console) I lose Czech accents (as in this example - notice the accented N and Č)

> "Ňuf ňuf ňufičky"
[1] "Nuf nuf nuficky"

I know it is a settings issue - I have other R installations that behave correctly - but I am unable to find exact place in my settings to force UTF-8 behavior. Any help would be appreciated.

My session info is:

R version 3.4.2 (2017-09-28)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.1252  LC_CTYPE=English_United States.1252    LC_MONETARY=English_United States.1252
[4] LC_NUMERIC=C                           LC_TIME=English_United States.1252    

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

loaded via a namespace (and not attached):
[1] compiler_3.4.2 tools_3.4.2    yaml_2.1.14   

Upvotes: 4

Views: 2723

Answers (2)

Jindra Lacko
Jindra Lacko

Reputation: 8749

For the benefit of posterity - I overcame my problem by setting code page to 1250 (while keeping US English as my language).

if (.Platform$OS.type == 'windows') {
  Sys.setlocale(category = 'LC_ALL','English_United States.1250')
} else {
  Sys.setlocale(category = 'LC_ALL','en_US.UTF-8')
}

in the .Rprofile

Upvotes: 4

IRTFM
IRTFM

Reputation: 263471

Perhaps:

new.locale <- ifelse(.Platform$OS.type=="windows", "Czech_Czech Republic.1250", "en_US.UTF-8")
Sys.setlocale("LC_CTYPE", new.locale) 

Also learn to specify your OS.

Upvotes: 1

Related Questions