Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assigning Arabic text to R variables

R doesn't display correctly Arabic text. I get very weird stuff when I use Arabic. Here's a screenshot:

enter image description here

The problem is that I want to create a wordcloud with Arabic text and I need to solve this problem first.

R version: R 2.15.2 GUI 1.53 Leopard build 64-bit (6335)

Here are more info:

> options("encoding")
$encoding
[1] "native.enc"

> Encoding("الله")
[1] "unknown"

SessionInfo():

> sessionInfo()
R version 2.15.2 (2012-10-26)
Platform: x86_64-apple-darwin9.8.0/x86_64 (64-bit)

locale:
[1] C/C/C/C/de_DE/C

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

loaded via a namespace (and not attached):
[1] tools_2.15.2
> 

Some tinkering:

> x = "مرحبا"
> Encoding(x) = "UTF-8"
> x
[1] "<U+0645><U+0631><U+062D><U+0628><U+0627>"
> Encoding(iconv(x))
[1] "unknown"

More info:

> Sys.getlocale()
[1] "C/C/C/C/de_DE/C"
> Sys.setlocale("LC_ALL", "en_US.utf8")
[1] ""
Warning message:
In Sys.setlocale("LC_ALL", "en_US.utf8") :
  OS reports request to set locale to "en_US.utf8" cannot be honored
> 

This solved the problem:

Sys.setlocale("LC_ALL", "en_US.UTF-8")
like image 766
Jack Twain Avatar asked Sep 07 '13 20:09

Jack Twain


1 Answers

This works:

Sys.setlocale("LC_ALL", "en_US.UTF-8")
like image 131
Jack Twain Avatar answered Sep 28 '22 06:09

Jack Twain