我在Rstudio中的代码中输入了一个密码,我只是想以某种方式使它不清楚所以当我向某人显示我的代码时他们看不到密码.有关如何做到这一点的任何建议?非常感谢
您可以在源文件中隐藏密码.
你可以运行类似的东西
dput(charToRaw("Password"))
# as.raw(c(0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64))
Run Code Online (Sandbox Code Playgroud)
获取密码的数字转储.然后,您可以在脚本中包含
pwd <- as.raw(c(0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64))
login("username", rawToChar(pwd))
Run Code Online (Sandbox Code Playgroud)
这至少会使它更不易被人类阅读,并且环境浏览器中没有带有文本值的变量(至少我认为,我不确定RStudio如何显示原始数据).
小智 6
你应该制作一个新的R脚本(让我们称之为login_credentials.R)并在那里存储你的密码
username <- "username_here"
password <- "password_here"
Run Code Online (Sandbox Code Playgroud)
保存后,您可以使用source()加载该脚本
这将加载用户名和密码变量.
source(login_credentials.R)
> username
[1] "username_here"
> password
[1] "password_here"
login_function(username,password)
Run Code Online (Sandbox Code Playgroud)