tags:

views:

117

answers:

2

Does R have a function that allows a user to provide a password securely, such as Python's getpass module?

(see http://docs.python.org/library/getpass.html for an example of what I mean)

A: 

What exactly would you be using this for? If its a web-based authentication there is a password authentication function in the Rcurl package.

Stedy
No, it's not for web-based authentication. I'm curious for general R-centric scripting purposes. If one doesn't exist then I'm going to write one myself. Just don't want to reinvent the wheel.
HamiltonUlmer
Sounds like it may just be easier to do it yourself then. Good luck!
Stedy
+2  A: 

The problem is that R does not have functions to control the terminal it is running in (something like Rncurses); probably this is due to portability issues.
Some time ago I was struggling with the same problem and I ended up with a function using TclTk:

getPass<-function(){  
  require(tcltk);  
  wnd<-tktoplevel();tclVar("")->passVar;  
  #Label  
  tkgrid(tklabel(wnd,text="Enter password:"));  
  #Password box  
  tkgrid(tkentry(wnd,textvariable=passVar,show="*")->passBox);  
  #Hitting return will also submit password  
  tkbind(passBox,"<Return>",function() tkdestroy(wnd));  
  #OK button  
  tkgrid(tkbutton(wnd,text="OK",command=function() tkdestroy(wnd)));  
  #Wait for user to click OK  
  tkwait.window(wnd);  
  password<-tclvalue(passVar);  
  return(password);  
}  

Of course it won't work in non-GUI environments.

mbq