2

Running a query using sqldf outputs garbled characters when the query results include characters such as: é,š.

When I checked the encoding of those fields in the original df, they are specifically UTF-8, but after the query with sqldf, they become "unknown" (which is the normal values if the string can be encoded using ASCII).

I converted the column to character (using as.character) but I still encounter this problem. In the documentation of sqldf I did not find a way to determine the query output encoding.

zx8754
  • 52,746
  • 12
  • 114
  • 209
dm-guy
  • 566
  • 3
  • 10
  • 1
    This works fine for me: `mydf <- data.frame(column=c("1","xéy","yyšxx"),stringsAsFactors=FALSE); sqldf("SELECT * FROM mydf")` – zx8754 Jan 25 '16 at 14:21
  • I am using Windows 8.1 and "R version 3.2.3 Patched (2016-01-12 r69945)" and zx8754's example works in Rgui for me too. – G. Grothendieck Jan 25 '16 at 15:28
  • Thank you for your reply. This works well for me too. I think it has to do with the fact that I import from CSV (working with RStudio). After view() of the df based on the CSV, the characters look fine. But when saving the query of sqldf to a new df, the characters are corrupted. So something has to tell sqldf to keep the utf-8 encoding, but I'm not sure how... (I do instruct R to do it explicitly when importing the CSV, using encoding=UTF-8, together with stringsasfactors=false). – dm-guy Jan 26 '16 at 09:50
  • ...I use Windows7; RStudio, 0.99.467.; R3.2.3. – dm-guy Jan 26 '16 at 09:57
  • Is there any solution to that problem? – S12000 Dec 18 '17 at 17:03

0 Answers0