gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 11:00:47 24 4
gpt4 key购买 nike

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

谢谢

最佳答案

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

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

OP JdeMello确认 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 - 如何在 R 中使用 system() 或 shell() 执行 git-bash 命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56069587/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com