如何在 R 中使用 system() 或 shell() 执行 git-bash 命令

How to execute git-bash command with system() or shell() in R

我想 运行 通过 system()shell() R 中的函数在 git-bash shell 中执行一些命令。我在 windows 默认 shell 是命令提示符。有什么方法可以将 system() 中的 shell 切换为 git-bash

谢谢

如果你的%PATH%包括C:\Program Files (x86)\Git\bin\,你应该可以系统调用:

bash --login -i -c "your command"

OP JdeMello confirms :

Yup: Didn't have C:\Program Files\Git\bin in PATH.

For completion, we can add Git\bin to PATH in R (if necessary):

if(length(grep("(?i)Git//bin", Sys.getenv("PATH"))) == 0) 
    Sys.setenv(PATH=paste0(Sys.getenv("PATH"),";C://Program Files//Git//bin")) 

That worked for me.