Is there a way in R to enter passwords interactively to the command line and hide them from the screen? I know there's readLine
, but I do not know passwords can be hidden there.
Assume you want to connect to a database using ROracle
or RMySQL
and do not want to store the password in a script but rather make the user enter it every time a query is executed.
Yes, we had a similar question around here, but I feel that the situation has changed and it's worth to address to problem again. Unfortunately tcltk
won't work on RStudio (Server).
However I have seen the folks at R Studio found a solution for their version control support. I remember previous versions where I could see my repo password every time I enter it in R Studio, but now that seems to be fixed. I know it's likely R Studio technique, but is there a way mortal R users can access it when working with R Studio Server?
Now that you have both R and RStudio on your computer, you can begin using R by opening the RStudio program. Open RStudio just as you would any program, by clicking on its icon or by typing “RStudio” at the Windows Run prompt.
Actually R Studio (Server) provides a nice solution. You can access it by using .rs
functions. They provide an undocumented password function which is really nice though there's no guaranteed support forever and a day:
.rs.askForPassword("foo")
You can find the the original hint from RStudio's Josh here: http://support.rstudio.org/help/discussions/questions/1448-password-interaction-with-dbs-on-rstudio-server
EDIT:
As of 2015 there is another nice solution to enter password interactively. You could use shiny
to have a little web based window with a password form. This discussion I had with @hadley shows an example snippet: https://github.com/rstats-db/RPostgres/issues/26
EDIT:
As of 2017 there is another update to this. @m-dz pointed us to this:
rstudioapi::askForPassword("Enter your pw")
as well as getPass::getPass()
from the R Studio Support webpage. Plus, I also realized that there is .rs.api.askForPassword()
which is equivalent to the initially suggested call - at least as far as I've seen.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With