R: can't read unicode text files even when specifying the encoding

后端 未结 1 793
一向
一向 2020-12-18 04:47

I\'m using R 3.1.1 on Windows 7 32bits. I\'m having a lot of problems reading some text files on which I want to perform textual analysis. According to Notepad++, the files

相关标签:
1条回答
  • 2020-12-18 05:08

    After reading more closely to the documentation, I found the answer to my question.

    The encoding param of readLines only applies to the param input strings. The documentation says:

    encoding to be assumed for input strings. It is used to mark character strings as known to be in Latin-1 or UTF-8: it is not used to re-encode the input. To do the latter, specify the encoding as part of the connection con or via options(encoding=): see the examples. See also ‘Details’.

    The proper way of reading a file with an uncommon encoding is, then,

    filetext <- readLines(con <- file("UnicodeFile.txt", encoding = "UCS-2LE"))
    close(con)
    
    0 讨论(0)
提交回复
热议问题