Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: provide an unmasked-input option #13

Closed
zkurtz opened this issue Jan 23, 2018 · 4 comments
Closed

Feature request: provide an unmasked-input option #13

zkurtz opened this issue Jan 23, 2018 · 4 comments

Comments

@zkurtz
Copy link

zkurtz commented Jan 23, 2018

getPass provides the only way I know to have an R script that is run from the command line prompt for user input. If you're willing to let people abuse your package for unintended use-cases, it would be very helpful if you could add an argument to allow intentional unmasking of input. For example: https://stackoverflow.com/questions/45932404/r-script-with-user-input-from-command-line/48405624#48405624

@wrathematics
Copy link
Owner

wrathematics commented Jan 23, 2018

I believe you can do this:

userInput<-function(question) {
  cat(question)
  readLines(stdin(), n=1)
}

@zkurtz
Copy link
Author

zkurtz commented Jan 23, 2018

If I do 'Rscript toy.R' from my command line, where 'toy.R' is

userInput = function(question) {
    readLines(stdin(), n=1)
}

x = userInput()
print(x)

then the script runs, but does not give me any opportunity to enter input. getPass is different in this regard - I have no idea how you achieved this.

@wrathematics
Copy link
Owner

Weird, it works for me. What OS are you using?

Based on notes in ?readLines and ?file, maybe try this:

userInput<-function(question) {
  cat(question)
  readLines(file("stdin"), n=1)
}

@zkurtz
Copy link
Author

zkurtz commented Jan 23, 2018

You are right!

I'm on OSX 10.12.6.

wrathematics pushed a commit that referenced this issue Mar 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants