How to set PATH on Windows through R “shell” command

前端 未结 3 1646
粉色の甜心
粉色の甜心 2021-02-06 08:57

I wish to add git to my PATH in Windows 7, through the \"shell\" command in R.

shell(\'set PATH=%PATH%;\"C:\\\\Program%20Files%20(x86)\\\\Git\\\\bin\"\', intern          


        
3条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-02-06 09:28

    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.

提交回复
热议问题