How to set PATH on Windows through R "shell" command How to set PATH on Windows through R "shell" command shell shell

How to set PATH on Windows through R "shell" command


If you want to permanantly update your path, then you pretty much had the answer:

shell('setx PATH "C:\\Program Files (x86)\\Git\\bin"')

R only notes a copy of the Windows environment variables when it starts up though, so strsplit(Sys.getenv("PATH"), ";") won't be different until you restart R.

Also, this won't run as with admin permissions (unless you set R as an administrator?) so it will add the path to the user path variable not the system one.


If you want R to see a different path in the current session, just use Sys.setenv.

Sys.setenv(  PATH = paste(    Sys.getenv("PATH"),     "C:\\Program Files (x86)\\Git\\bin",     sep = ";"  ))

This won't make permanant changes to the path. Only R can see this change, and only until you close it.


When you run shell, a new process is created. In Windows, this will run CMD.EXE and pass the arguments given. Then this process exits.

When you modify the environment variable, you are modifying in a subprocess of R and not in the R process itself. When the subprocess dies, so does its environment.

You should set the path appropriately before you start R instead.


Regarding

what is the issue?

You're just changing the PATH environment variable in the new command interpreter process.


You can use the setx command to change the PATH defaults, but that does not affect your current process.

What to do depends a bit on what you're trying to achieve.