2

So this works:

odbcConnect("TestDB", "admin", "password")

but I dont want the username and pwd in clear text. I figured simply write the credentials to a text file and import that file for use with:

odbcConnect(textFile)

Saving the credentials and calling readLines(textFile) produces a string with escape characters that throws the connections:

"odbcConnect(\"TestDB\", \"admin\", \"password\")"

I've tried legion of escape characters in the text file and also tried creating a string using paste but the result always comes back to a version of the line above. Anyone got a workaround or safer way to connect to SQL?

1 Answer 1

2

You can store the variables in a separate .r file.
username = yourusername password = yourpassword dsn = yourDB

In the script where you connect the ODBC you can then call the script that defines those variables. source("variables.r")

2
  • That makes sense ... I should have / wish I'd thought of that! Thanks for taking the time - was driving me nuts.
    – felixmc
    Nov 4, 2014 at 10:42
  • I took it a step further and simply source a connection to the database script, then the variables never enter the session.
    – Badger
    Sep 27, 2017 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.