I've got multiple SQL-Queries (and R-calculations) distributed over several files, which should be executed using sqlQuery()
from the RODBC
package. Each file opens its own connection thoughodbcConnect()
. The scripts are delivering the desired results as long as the queries are called within their according R-script.
However, once I try to execute the scripts from another meta-file via source()
-functions I get an error (invalid character) from the queries containing non-UTF-8 characters.
Now I tried to specify different encodings using
odbcConnect(DBMSencoding = "")
odbcConnect(DBMSencoding = "UTF-8")
odbcConnect(DBMSencoding = "UTF8")
odbcConnect(DBMSencoding = "ASCII")
odbcConnect(DBMSencoding = "ANSI")
which doesn't change the results.
Using the following command tells me that the enconding of the database (NLS_CHARACTERSET
) is UTF8
(Oracle database).
SELECT *
FROM NLS_DATABASE_PARAMETERS
WHERE PARAMETER IN ('NLS_CHARACTERSET');
However, I can't make the queries containing non-UTF-8 characters work as I want them to.
Is the encoding the actual problem when trying to execute SQL-Queries in R-Scripts using source()
?
And are there any suggestions how to make it work?
Thank you in advance!
[EDIT] Here's a short reproducable example of my problem:
df <- sqlQuery(channel, paste(
"
SELECT NR AS TÄST
FROM TEST.DATA
",
sep = ""))
This works within the R-script, but it gives me the following error when calling the script using source((paste(path, "script.R", sep=""), print.eval=TRUE, echo=TRUE)
:
"HY000 911 [Oracle][ODBC][Ora]ORA-00911: Invalid character\n"
Changing "TÄST" to "TEST" or even "TÜST" works, since "TÜST" is converted to "TÃŒST". Thus, I'm assuming that there's a problem with the encoding.