getPass (version 0.1-1)

getPass: Password Input

Description

Password reader. Like R's readline() but the user-typed input text is not printed to the screen.

Usage

getPass(msg = "PASSWORD: ", forcemask = FALSE)

Arguments

msg

The message to enter into the R session before prompting for the masked input. This can be any single string, including a "blank", namely "".

forcemask

Logical; should the function stop with an error if masking is not supported? If FALSE, the function will default to use readline() with a warning message that the input is not masked, and otherwise will stop with an error.

Value

If input is provided, then that is returned. If the user cancels (e.g., cancel button on RStudio or ctrl+c in the terminal), then NULL is returned.

Details

Masking (i.e., not displaying the literal typed text as input) is supported on most, but not all platforms. It is supported in RStudio, provided you have a suitable version of the GUI. It should also work in the terminal on any major OS. Finally, it will work in any environment where the tcltk package is available.

In the terminal, the maximum length for input is 200 characters. Additionally, messages printed to the terminal (including the "*" masking) are printed to stderr.

Examples

Run this code
# NOT RUN {
# Basic usage
getPass::getPass()

# Get password with a custom message
getPass::getPass("Enter the password: ")
# }
# NOT RUN {
# }

Run the code above in your browser using DataCamp Workspace