[R] Add permanently environment variable

Joshua Wiley jwiley.psych at gmail.com
Sat Jul 16 04:18:15 CEST 2011


On Fri, Jul 15, 2011 at 1:45 PM, Anna Lippel <lippelanna21 at hotmail.com> wrote:
> Hello everyone, I know how to add a folder path to my EV path but it only
> works for the current R session. Is there a way to add it permanently? Here

Yes, you can add it permanently using Windows.  If you are on Windows
7, something like this should work:

WindowsKey + R   (to bring up the run console)
powershell RET (to bring up the powershell)

# Create a new variable with the path to Java
$newpath = "C:\Program Files\Java\jre1.6.0_13\bin;"
# add the contents of the machine path to the above
$newpath += [environment]::GetEnvironmentVariable("PATH", "Machine")
$newpath # verify this is correct

# now set the environment variable "PATH" to the contents of $newpath
[Environment]::SetEnvironmentVariable("PATH", $newpath, "Process")

# Check that things look as they should (again)
[Environment]::GetEnvironmentVariable("PATH", "Process")

# Note that where I put "Process" you would need to put
# "Machine" if you want it to be permanent
# but be careful because you could really mess things up
# which is why I left it at the Process level which will be trashed
# when you exit that session of the powershell

Another, perhaps simpler option would be to use the control panel.
Searching for windows set environment variable will bring up countless
guides.

HTH,

Josh

> is my code:
> Sys.setenv(PATH=paste("C:\\Program Files\\Java\\jre1.6.0_13\\bin;",
> Sys.getenv(x="PATH"), sep=""))
> Thanks a lot!
>
> --
> View this message in context: http://r.789695.n4.nabble.com/Add-permanently-environment-variable-tp3670920p3670920.html
> Sent from the R help mailing list archive at Nabble.com.
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.

-- 
Joshua Wiley
Ph.D. Student, Health Psychology
University of California, Los Angeles
https://joshuawiley.com/



More information about the R-help mailing list