[R] Trouble reading a UTF-16LE file

Ivan Krylov |kry|ov @end|ng |rom d|@root@org
Wed Feb 28 15:12:56 CET 2024

В Wed, 28 Feb 2024 13:44:49 +0000
"Ebert,Timothy Aaron" <tebert using ufl.edu> пишет:

> readLines(file, encoding='utf-16LE')

There are two ways you could encounter an encoding in R.

First are encoding markers placed on every string object, which declare
the string to be encoded in UTF-8, Latin-1, the native locale encoding,
or ASCII or "bytes". No other encodings are supported. The "encoding"
argument of readLines() sets this marker.

In order to support other encodings, R is able to convert the text as
part of the input/output connections. help(readLines) points you
towards that: you need to set the UTF-16LE encoding on the connection

con <- file(file, encoding = 'UTF16LE')
lines <- readLines(con)

"UTF16LE" is not guaranteed to be supported, so see iconvlist() for the
encodings that should work with your build of R.

Best regards,

More information about the R-help mailing list