Reputation: 1321
I encountered a problem of lossing file encoding UTF - 8 when using
read.csv
in R. That resulted in e.g. Latin letters replaced by not desired signs, e.g.: Iguaçu.
I tried using following with FileEncoding argument:
read.csv(xx.csv, fileEncoding = 'UTF-8')
read.csv2(xx.csv, fileEncoding = 'UTF-8')
but got error:
Warning messages:1: In read.table(file = file, header = header, sep = sep, quote = quote, :
invalid input found on input connection 'C:/xxx.csv'
2: In read.table(file = file, header = header, sep = sep, quote = quote, :
incomplete final line found by readTableHeader on 'C:/xxx.csv'
What is the solution to keep the UTF-8 encoding when reading csv into R?
Upvotes: 1
Views: 4039
Reputation: 1321
So by trial and error method, I found out that using function from readr
package
read_csv
instead of
read.csv
read.csv2
without any fileEncoding argument does the work and the encoding is being kept. Hope that might help someone.
Upvotes: 3