如何在R中使用system()或shell()执行git-bash命令 [英] How to execute git-bash command with system() or shell() in R

查看:111
本文介绍了如何在R中使用system()或shell()执行git-bash命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过R中的 system() shell()函数在 git-bash shell中运行一些命令.我是在Windows上,默认外壳是命令提示符.有什么办法可以将 system()中的shell切换为 git-bash ?

谢谢

解决方案

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

  bash --login -i -c您的命令" 

OP JdeMello 确认

对我有用.

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

解决方案

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.

这篇关于如何在R中使用system()或shell()执行git-bash命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆