I have an R script that runs perfectly when run from Rstudio. It uses an .Renviron
file to provide environment variables which are visible in Sys.getenv()
(so I know it works).
However, when I run the exact same script via powershell, the R script mysteriously doesn't find those environment variables (I confirmed this by print(Sys.getenv())
- the environment variables provided through .Renviron
are nowhere to be seen.
Why aren't the .Renviron
variables being found when the R script is run from powershell (as opposed to when the script is run in RStudiom, where everything works)
The .Renviron
file is currently saved in "C:/Users/Administrator/Documents/.Renviron"
Inspecting normalizePath(Sys.getenv('R_HOME'))
returns "C:\\Program Files\\R\\R-3.6.0"
, so I also tried putting .Renviron
there. No luck
Based on this I also tried Sys.getenv("C:/Users/Administrator/Documents/.Renviron")
, but again no luck
This is what worked for me
path_to_Renviron_file <- "C:/Users/Administrator/Documents/.Renviron"
readRenviron(path_to_Renviron_file)