Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

r

git-bash

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

like image 851
JdeMello Avatar asked Nov 06 '22 17:11

JdeMello


1 Answers

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.

like image 188
VonC Avatar answered Nov 14 '22 22:11

VonC