在R或R Studio(服务器)中以交互方式输入密码? [英] Enter passwords interactively in R or R Studio (Server)?

查看:336
本文介绍了在R或R Studio(服务器)中以交互方式输入密码?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

R中是否有一种方法可以交互式地向命令行输入密码并将其隐藏在屏幕上?我知道这里有readLine,但我不知道密码可以在那里隐藏. 假设您要使用ROracleRMySQL连接到数据库,并且不想将密码存储在脚本中,而是希望用户在每次执行查询时都输入密码.

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")以及getPass::getPass() rel ="noreferrer"> R Studio支持网页.另外,我还意识到.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆