RStudio and SVN: How to prompt connection details and how to avoid hard coding?

StackOverflow https://stackoverflow.com/questions/19891727

  •  30-07-2022
  •  | 
  •  

Вопрос

I'm using RStudio and SVN repository to version control my R projects and files. Usually I fetch data from database at the beginning in these scripts. I'm using RODBC like this:

channel <- odbcConnect(mydbconn, uid = "", pwd = "")

Now, I don't want to store connection details, user id's and password's in these scripts because if these are hard coded, everyone who can access to SVN repo is able to see my passwords etc.

What is the best approach in these kind of cases? How can I prompt these details (connection, userid and password) when this script is run (e.g from RStudio or from the command line)?

Это было полезно?

Решение

If you want to prompt the user, you can use the [readline][1] method:

connection <- readline("Connection: ")
uid <- readline("User id: ")
cat("Password: ")
system("stty -echo")
password <- readline()
system("stty echo")

Note the little trick to avoid echoing the password to the screen.

Another option is to store those values in a configuration file (e.g. config.local) and insert load(config.local) in the script. Make sure that file is not versioned with svn propset svn:ignore "config.local . ". Alternatively, you can store that file in a directory which is not under the control of svn.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top