I have production ready R script, and from R script fetching some data from Oracle database,For dev I have hardcoded it , How to authenticate in production?
Two options come to my mind:
- read the value from a configuration file (and just switch a dev / prod version of the
config.txtfile); this has possible extra benefit that you can gitignore the file if storing on GitHub or other public server
- if the script is run in RStudio you can ask the user for authentication by calling
secret <- rstudioapi::showPrompt(title = "Client Secret", message = "Client Secret", default = "")
or something along similar lines...
The 'config' package is a great way to formalize the approach from your first suggestion.
It works really well for that sort of thing and means you can seamlessly deploy to test or prod and everything just works.
Just for curiosity which is the advantage of using
config over setting your credentials in your renviron.site file?
For credentials it probably does not really matter.
But in principle: when working on bigger projects I found it advantageous to have separate configuration file - I am not familiar with the
config package - as either a text file or an entry in codebook table in database.
One advantage I mentioned already is version control - it is difficult to version control the contents of your renviron file; much more easily done with a small text file.
Another advantage is that you can easily have the config file temporary in nature - say if you have parameters governing a complicated migration. You have a version for development, another for testing (perhaps different ones for several rounds of testing) and then a production version, which you later replace with a "clean" production code in a later release.
For getting rid of the no-longer-required parameter it is easier to remove a file / entry in a codebook database than deleting an entry in renviron file.
There’s been a fair bit of discussion on similar topics before — you might look st these threads for some more ideas:
This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.
If you have a query related to it or one of the replies, start a new topic and refer back with a link.