Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

R database connection encoding mistakes with accents

I am connecting to a SQL Server database using this code:

DBI::dbConnect(odbc(), 
               Driver = "...", 
               Server = "...", 
               Database = "...", 
               UID = "...", 
               PWD = "...", 
               Port = ...)

And later I amb extracting a table using the function dbGetQuery.

The problem is that I have columns with accents (spanish language) in the SQL Server, I can see them correctly there, but when I get the table in R I cannot see them correctly, I see the symbol ďż˝ in the letters with accents.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How could I fix that?

>Solution :

It should work to add the argument encoding = <the encoding of your database> to DBI::dbConnect().

Do you know the encoding your database is using? If not, I would try latin1 first, as that is rather common for western european languages (se e.g. here).

So try changing your code to:

DBI::dbConnect(
  odbc::odbc(), 
  Driver = "...", 
  Server = "...", 
  Database = "...", 
  UID = "...", 
  PWD = "...", 
  Port = "...",
  encoding = "latin1"
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading