如何隐藏R studio上的值或不显示值但可以使用?

How can I hide the value on the R studio or do not show the value but it can be used?

例如:

Script_1.R: AC <- 'tester' Password <- '123456'

Script_2.R:

source('Script_1.R') dbConnect(user = AC, password = password)

我想隐藏 R studio 上显示的值,但它可以在我需要连接数据库时使用。 此外,我想让密码 '123456' 显示 ****** 但值等于 123456.

我该怎么办?谢谢

由于您使用的是 RStudio,因此您可以使用 rstudioapi::askForPassword(),它会启动一个弹出窗口供您输入密码。

如果您直接将其放入您的代码中,您输入的文本将不会保存到您的环境中:

dbConnect(user = AC, password = rstudioapi::askForPassword())