本文介绍了R:调用系统命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用系统命令从 R 代码中调用一个可执行文件.如果我在终端中使用命令行调用 R,然后执行 system("mothur").但是,如果从 R 脚本(在 RStudio 上)中执行相同的命令,我会得到:sh: mothur: command not found.

I was trying to invoke an executable from within R code using the system command. If I use command line in a terminal to invoke R, and then execute system("mothur"). However, if from within an R script (on RStudio) I execute the same command, I get: sh: mothur: command not found.

在这两种情况下,当前工作目录是相同的.

In both cases, the current working directory is the same.

我需要以不同的方式调用命令吗?

Do I need to invoke the command in a different manner?

谢谢!

推荐答案

我正在努力在我自己的系统上复制这个问题,但我认为答案是调用 which 并使用输出以打开应用程序.如果 which 在系统命令行中使用时提供正确的路径,这应该可以工作:

I'm stuggling to replicate this problem on my own system, but I think the answer would be to call which and use the output to open the application. This should work if which provides the correct path when used in the system command line:

system("$(which mothur)")

这篇关于R:调用系统命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:48