Importing a .csv into R with UTF-8 encoding error?

18,909

Solution 1

You need to specify the encoding

servutf <- read.csv("servutf.csv", sep=";", encoding = "UTF-8")

Solution 2

Try:

library(readr)
servutf <- read_csv("servutf.csv")
Share:
18,909
adrian1121
Author by

adrian1121

I am an enthusiast of Data Science and Data Visualization. I work extensively with R along with Python or Stata to get the full image of a problem. Currently I'm doing my PhD in Machine Learning.

Updated on June 25, 2022

Comments

  • adrian1121
    adrian1121 almost 2 years

    I have a .csv file which is written in spanish so it has special characters like ñ, á, é, í, ó, ú. So if I open it in the notepad I can see all the characters properly written and I have already saved the file with UTF-8 encoding. However, when I open RStudio and I import the data using:

    servutf <- read.csv("servutf.csv", sep=";")
    

    I get all the dataset but incorrectly encoded i.e.:

    Tengo 7 años de experiencia
    

    It should be the following:

    Tengo 7 años de experiencia
    

    I have tried everything, I don't know what else to do as I have already checked that R is using UTF-8 encoding and the file is encoded in the same way.

    Any suggestion please?