.Renviron File Not Working

Hey folks - I'm having a problem with my .Renviron file. I have scripts that reference environment variables for passwords that work fine on my laptop but do not work on my remote desktop.

My desktop has an .Renviron file with the following:
PASSWORD = "123456789"

When I load R on my remote desktop and try to retrieve the password, this is what happens:
[1] ""

Also, when I try to the usethis package to edit the .Renviron file (usethis::edit_r_environ()), I get an "access denied" dialog box.

Any thoughts on how I can get the .Renviron file to work?


It's worth checking that you're putting the .Renviron in the right place. If so, its possible you have a file permissions issue - that might explain why you're getting 'access denied'.

What operating system are you using? If Linux or Mac you could probably view the file ownership & permissions by running this from an R session:

system(sprintf('ls -al %s', Sys.getenv('R_ENVIRON_USER')))

Thanks for your response! I have the .Renviron file in the C:\Users[USERNAME]\Documents folder, which I think is the default location?

That's what I was thinking to. Both my laptop and remote desktop are Windows and are managed by my employee so I don't have admin rights. I can open the .Renviron file in a text editor to change though.

So I did some digging and noticed that the my laptop's Windows environment variables were different from my desktop's Windows environment variables. Specifically on my desktop there was an extra R User environment variable that was pointing to my Windows Documents folder, which was not on my laptop. I removed that extra environment variable from my desktop and now I can retrieve values from .Renviron file.

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.