Exit Cyrillic Encoding to R

Coding is always a pain for me, and again it is impossible to write a file with Russian text. What should I do for this?

>test = c("","") >test [1] "\320\277\321\200\320\270\320\262\320\265\321\202" "\320\277\320\276\320\272\320\260" >Encoding(test) [1] "unknown" "unknown" > f = file("test.txt", encoding = "UTF-8") > write(t,f) Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'closure') cannot be handled by 'cat' > Encoding(test) = "UTF-8" > test [1] "<U+043F><U+0440><U+0438><U+0432><U+0435><U+0442>" "<U+043F><U+043E><U+043A><U+0430>" > write(t,f) Error in cat(list(...), file, sep, fill, labels, append) : argument 1 (type 'closure') cannot be handled by 'cat' 

I am using R-studio 0.97.312, Mac OS 10.7.5,

+3
source share
2 answers

I know your pain about encoding issues :( Hope this helps you:

  > Sys.setlocale(,"ru_RU") [1] "ru_RU/ru_RU/ru_RU/C/ru_RU/C" > test = c("","") > write(test, file="test.txt") 

You can even use cyrillic variables after this Sys.setlocale(,"ru_RU") :

  >  <- rnorm(100) > min() [1] -2.54578 

So good luck! :)

+1
source

If you just go to the Encoding () help page, you will find the enc2native (x) built-in function, this will do the trick, as in

 test = enc2utf8(c("","")) 
+1
source

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


All Articles