Enter passwords interactively in R or R Studio (Server)?

前端 未结 1 606
后悔当初
后悔当初 2021-01-30 23:49

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

相关标签:
1条回答
  • 2021-01-31 00:41

    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.

    0 讨论(0)
提交回复
热议问题