2

I wonder if it is possible to get password from R command line. I have tried several variants of the following, but characters are echoed on the screen when entered.

password = scan(file = "", what = character(), nmax = 1)
M.Qasim
  • 1,827
  • 4
  • 33
  • 58

1 Answers1

4

You need a UI component that knows a password is typed, and hence shows the stars.

The only portable one is part of the tcltk package, and has been recommended a few times in the past.

Edit: The getPass package provides a wrapper to several underlying approaches.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • 1
    Relevant question with the tcltk package versions that works in GUI environments, but not on the command line: http://stackoverflow.com/questions/2917202/way-to-securely-give-a-password-to-r-application – Mekki MacAulay Feb 11 '16 at 19:40
  • 2
    Just found a working solution for me provided by RStudio .rs.askForPassword("foo"). It does not have much documentation though. – M.Qasim Feb 11 '16 at 19:57
  • 2
    Was just browsing for this and on an [RStudio support webpage](https://support.rstudio.com/hc/en-us/community/posts/115000470088-function-rs-askForPassword-and-R-Markdown) `rstudioapi::askForPassword("")` is mentioned as a preferred function when using RStudio, also `getPass::getPass()` function is mentioned there which seems to be a more versatile solution. – m-dz Mar 06 '17 at 11:49