在R或R Studio(服务器)中以交互方式输入密码? [英] Enter passwords interactively in R or R Studio (Server)?
问题描述
R中是否有一种方法可以交互式地向命令行输入密码并将其隐藏在屏幕上?我知道这里有readLine
,但我不知道密码可以在那里隐藏.
假设您要使用ROracle
或RMySQL
连接到数据库,并且不想将密码存储在脚本中,而是希望用户在每次执行查询时都输入密码.
Is there a way in R to enter passwords interactively to the command line and hide them from the screen? I know there's readLine
, but I do not know passwords can be hidden there.
Assume you want to connect to a database using ROracle
or RMySQL
and do not want to store the password in a script but rather make the user enter it every time a query is executed.
是的,我们有一个类似的问题在这附近,但我认为情况已经改变,值得再次解决问题.不幸的是,tcltk
在RStudio(服务器)上不起作用.
Yes, we had a similar question around here, but I feel that the situation has changed and it's worth to address to problem again. Unfortunately tcltk
won't work on RStudio (Server).
但是,我看到R Studio的人们找到了他们的版本控制支持解决方案.我记得以前的版本,每次我在R Studio中输入回购密码时都可以看到我的回购密码,但是现在这个问题似乎已经解决了.我知道这很可能是R Studio技术,但是凡人R用户在使用R Studio Server时是否可以使用它?
However I have seen the folks at R Studio found a solution for their version control support. I remember previous versions where I could see my repo password every time I enter it in R Studio, but now that seems to be fixed. I know it's likely R Studio technique, but is there a way mortal R users can access it when working with R Studio Server?
推荐答案
实际上,R Studio(服务器)提供了一个不错的解决方案.您可以使用.rs
功能访问它.他们提供了一个未公开的密码功能,尽管永远无法保证每天提供支持,这确实很棒:
Actually R Studio (Server) provides a nice solution. You can access it by using .rs
functions. They provide an undocumented password function which is really nice though there's no guaranteed support forever and a day:
.rs.askForPassword("foo")
您可以在此处找到RStudio的Josh的原始提示: http://support.rstudio .org/help/discussions/questions/1448-password-interaction-with-dbs-on-rstudio-server
You can find the the original hint from RStudio's Josh here: http://support.rstudio.org/help/discussions/questions/1448-password-interaction-with-dbs-on-rstudio-server
截至2015年,还有另一个不错的解决方案,可以交互式输入密码.您可以使用shiny
来创建一个带有密码表单的基于Web的小窗口.我与@hadley进行的讨论显示了一个示例片段: https://github.com/rstats -db/RPostgres/issues/26
As of 2015 there is another nice solution to enter password interactively. You could use shiny
to have a little web based window with a password form. This discussion I had with @hadley shows an example snippet: https://github.com/rstats-db/RPostgres/issues/26
截至2017年,对此进行了另一次更新. @ m-dz向我们指出了这一点:
rstudioapi::askForPassword("Enter your pw")
以及.rs.api.askForPassword()
相当于最初建议的呼叫-至少就我所知.
As of 2017 there is another update to this. @m-dz pointed us to this:
rstudioapi::askForPassword("Enter your pw")
as well as getPass::getPass()
from the R Studio Support webpage. Plus, I also realized that there is .rs.api.askForPassword()
which is equivalent to the initially suggested call - at least as far as I've seen.
这篇关于在R或R Studio(服务器)中以交互方式输入密码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!