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

别说谁变了你拦得住时间么 提交于 2021-02-19 04:19:39

问题


I would like to run some command in git-bash shell via system() or shell() functions in R. I am on windows and the default shell is the command prompt. Is there any way I can switch the shell in system() to git-bash?

Thank you


回答1:


If your %PATH% includes C:\Program Files (x86)\Git\bin\, you should be able to system call:

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

The OP JdeMello confirms in the comments:

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.



来源:https://stackoverflow.com/questions/56069587/how-to-execute-git-bash-command-with-system-or-shell-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!