I'm having trouble changing the "locale" when using the DBI package in R. More specifically, my database contains characters such as "é, è, ê, ..." and DBI does not read them correctly.
When I perform the same query using the RODBC package, it does get me the correct result. My question: how can I get the correct result (i.e. reading "é, è, ê, ..." correctly) with the DBI package?
This should be a reproducible example:
sql <- "select * from myDatabase.dbo.myTable"
# Where myTable contains any of the difficult characters
# Try with DBI
library(odbc)
library(DBI)
conDBI <- dbConnect(
odbc::odbc(),
dsn = "myDsn",
UID = myLogin,
PWD = myPassword,
Port = 1433
)
table_DBI <- dbGetQuery(conDBI, sql)
# Try with RODBC
library(RODBC)
conRODBC <- odbcConnect(
"myDsn",
uid = myLogin,
pwd = myPassword
)
table_RODBC <- sqlQuery(conRODBC, sql)
In case this is relevant, here's my session info:
> sessionInfo()
R version 3.4.0 Patched (2017-06-02 r72765)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1
Matrix products: default
locale:
[1] LC_COLLATE=Dutch_Belgium.1252 LC_CTYPE=Dutch_Belgium.1252 LC_MONETARY=Dutch_Belgium.1252 LC_NUMERIC=C
[5] LC_TIME=Dutch_Belgium.1252
attached base packages:
[1] stats graphics grDevices utils datasets tools methods base
other attached packages:
[1] RODBC_1.3-15 DBI_0.6-1 odbc_1.1.1
loaded via a namespace (and not attached):
[1] bit_1.1-12 compiler_3.4.0 hms_0.3 tibble_1.3.3 Rcpp_0.12.11 bit64_0.9-7 blob_1.1.0 rlang_0.1.1