On mac (or linux)
Open the terminal and type
touch $HOME/.Renviron
To open the file you just created, navigate through finder to /Users/<your-user-name>/.Renviron
, or simply open the terminal and type
open $HOME/.Renviron
On windows
Click on start and open powershell. Copy this code into powershell
Add-Content c:Users$env:USERNAMEDocuments.Renviron "TEST_VARIABLE_1=my_username"
Add-Content c:Users$env:USERNAMEDocuments.Renviron "TEST_VARIABLE_2=123"
You'll now have a file called .Renviron
located in the Documents
folder. Close and reopen RStudio. Then run Sys.getenv('TEST_VARIABLE_1')
to access the variable in R (obviously that works for any other environment variables you set as well).
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…