I'd like to revisit an old SO question about passwords. Like the OP, I don't want to enter my password interactively, but I am confused about how to store the password securely on my machine and share scripts with colleagues (and I'd add specifically, push scripts to GitHub). The accepted answer involves storing the password in .Rprofile
, but one commenter suggests that this is not a good idea.
In my specific use case, I have a script that runs every day on a virtual machine that I want other members of my team to access. At the end of the run, it sends an email with the mailR
package. This code looks for my gmail password. I've set up 2-step authentication, so mypassword
is a third-party password, not my actual gmail password. Still, I am hesitant to share this with others. I'd like to be able to push the script to a private git repo.
send.mail(from = "myemail@gmail.com",
to = tolist,
subject = "my subject",
body = "my message",
smtp = list(host.name = "smtp.gmail.com", port = 465,
user.name = "myusername",
passwd = "mypassword",
ssl = TRUE),
authenticate = TRUE,
html = FALSE,
send = TRUE)
How would you store mypassword
?
Storing it in
.Rprofile
seems to be an option, but I don't know if there are downsides like the one mentioned in response to the accepted answer in the question I linked to.I could store it in another file like
auth.R
and runsource('auth.R')
beforesend.mail
, but this would put the password in the global environment.Other ideas?