getPass is an R package for reading user input in R with masking. The package can be installed with the usual
install.packages(). There is one exported function,
getPass(), which will behave as R’s
readline() but with masked input. You can pass a message to the password input via the
msg argmuent, similar to the
prompt argument in
To use this with RStudio, you need:
In this case, the
getPass() function wraps the rstudioapi function
Here, the input reader is custom. It has been tested successfully on Windows (in the “RTerm” session), Mac (in the terminal, not R.app which will not work!), and Linux. The maximum length for a password in this case is 200 characters.
On Windows, the reader is just
_getch(). On ’nix environments (Mac, Linux, …), masking is made possible via
tcsetattr(). Special handling for each is provided for handling ctrl+c and backspace.
If you discover an issue, please file an issue report.
If you use RGui (the Windows R GUI), then this should use the tcltk package. I don’t think it’s actually possible for tcltk to be unavailable on Windows, so if you are an RGui user and have trouble with this, please file an issue report.
You will need to install dependencies for the tcltk package. I’m not completely sure what this process involves for Macs; if you know, please let us know. If tcltk is unavailable, then it will use the “unsupported” method below.
When a platform is unsupported, the function will optionally default to use R’s
readline() (without masking!) with a warning communicated to the user, or it can stop with an error.
We thank Kevin Ushey for his assistance in answering questions in regard to supporting RStudio.
The development for this package was supported in part by the project Harnessing Scalable Libraries for Statistical Computing on Modern Architectures and Bringing Statistics to Large Scale Computing funded by the National Science Foundation Division of Mathematical Sciences under Grant No. 1418195.
Any opinions, findings, and conclusions or recommendations expressed in this material are those of the authors and do not necessarily reflect the views of the National Science Foundation.