Alif
Alif

Reputation: 28

readlines files in r with differents encoding

I have :

guess_encoding("file.txt")$encoding
[1] "UTF-8"      "ISO-8859-1" "ISO-8859-2"

I want to read my file :

lines <- readLines("file.txt", encoding = guess_encoding("file.txt")$encoding)

but it return this error

Error in readLines("file.txt", encoding = guess_encoding("file.txt")$encoding) : 
  invalid 'encoding' value

Upvotes: 0

Views: 34

Answers (1)

Nir Graham
Nir Graham

Reputation: 5167

you showed that guess_encoding (from readr) made 3 guesses

"UTF-8" "ISO-8859-1" "ISO-8859-2"

to pick the first guess and try to use it would be


 lines <- readLines("file.txt", encoding = guess_encoding("file.txt")$encoding[[1]])

Upvotes: 0

Related Questions