Reputation: 119
I am trying to make use of RMysql package to connect with mysql database and fetch data from it. While importing into R it is changing the encoding format from utf8 thus a records which is "Córdoba" in UTF-8 is returned as "Córdoba".
I have tried many things from few post from Stackflow but with no success.
I have tried to set the names as utf 8 using the command and few other thing as
dbGetQuery(mydb,'set character set "utf8"')
It looks that i am missing at something. Really looking for someone who can guide me to the resolution as it has become a show stopper for me. Kindly help please.
Upvotes: 3
Views: 1093
Reputation: 31
I could solve the same problem with:
dbSendQuery(conn, 'set character set "utf8"')
data <- dbReadTable( conn, "name")
Upvotes: 1
Reputation: 119
For anyone who is looking for the resolution to it, i would like to mention it. After exporting the data from SQL into R either using dbGetQuery or dbSendQuery, function "iconv" can be executed on the table's vectors to convert it into utf8 format. Bekow is the code example of extracting the data and converting it into utf8 format.
rs = dbSendQuery(mydb, "select * from dim_survey_response_alignment")
alignfile = fetch(rs, n=-1)
alignfile <- subset(alignfile, select = c("attribute","response","aligned"))
alignfile$response <- iconv(alignfile$response,from = "UTF-8")
Enjoy Learning
Upvotes: 3