4

I have been trying to read and output a Hindi .txt file into the R console but I get gibberish. This is what I did so far.

hindi <- read.table('hindi_text.txt')
hindi

1 कà¥à¤¯à¤¾ बोल रहे हो तà¥à¤®

Then I typed this. It still does not work.

> Sys.setlocale(category="LC_ALL", locale="hindi")
> [1] "LC_COLLATE=Hindi_India.1252;LC_CTYPE=Hindi_India.1252;LC_MONETARY=Hindi_India.1252;LC_NUMERIC=C;LC_TIME=Hindi_India.1252"
> hindi
> 1 कà¥à¤¯à¤¾ बोल रहे हो तà¥à¤®

I tried this with reading Chinese characters by changing the locale to Chinese and it worked.

> chinese <- read.table("chinese.txt")
> Sys.setlocale(category="LC_ALL", locale="chinese")
> [1] "LC_COLLATE=Chinese (Simplified)_China.936;LC_CTYPE=Chinese (Simplified)_China.936;LC_MONETARY=Chinese (Simplified)_China.936;LC_NUMERIC=C;LC_TIME=Chinese (Simplified)_China.936"
> chinese
> 1 锘夸负浠€涔堣繖涓敞鎰忥紝杩欎釜宸ヤ綔

Why does this work with Chinese and not Hindi (and some other languages too) and is there any way I can make it work?

Chthonic Project
  • 8,216
  • 1
  • 43
  • 92
  • Never tried that before, but RStudio was able to do gsub with some hindi text when I tried just now. If you are using Rstudio, can you paste some hindi text onto console? It was jittery for me, but it worked. There is an **encoding** parameter to read.table, BTW. It might work. – R.S. Jul 22 '15 at 17:27
  • Yes, pasting texts work. But reading .txt or .csv files containing Hindi doesn't work. – slingblade8129 Jul 22 '15 at 17:37
  • 2
    This page seems to be useful : [link] https://support.rstudio.com/hc/en-us/articles/200532197-Character-Encoding It says changing locale while RStudio is running might not work as expected. Also, there are read.table examples. – R.S. Jul 22 '15 at 17:57
  • As you are using RStudio , you can try importing the text file through the menu Tools > Import Dataset > From Text File. It has a number of options, all in gui. – R.S. Jul 22 '15 at 18:49
  • Might want to check this: http://stackoverflow.com/questions/10955582/displaying-utf-8-encoded-chinese-characters-in-r?rq=1 – Utkarsh Jul 25 '15 at 06:37
  • have a look at readtext package.. I'm not sure yet – Indranil Gayen Nov 27 '17 at 05:58

0 Answers0