无法 运行 在 R 中使用 system() 进行编程

Cannot run program using system() in R

我正在尝试使用 system().

在 R 脚本中从包 deepTools 运行 computeMatrix

以下命令会收到此错误消息。

system('computeMatrix --help')

sh: computeMatrix: command not found
Warning message:
In system("computeMatrix --help") : error in running command

但是,如果我 运行 终端中的相同命令一切正常。


sessionInfo()

R version 4.0.4 (2021-02-15)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Big Sur 10.16
Matrix products: default
LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib

这是 Ubuntu 20.04 中的 运行。
运行宁系统命令的推荐方式是使用system2,而不是system。参数在向量中传递,args。在这种情况下 args 是一个长度为 1 的向量,但如果有多个参数,则将它们作为

传递
args <- c("arg1", "arg2", etc)

此命令按预期工作。

cmd <- "computeMatrix"
args <- "--version"
system2(cmd, args)
#computeMatrix 3.3.2

sessionInfo()
#R version 4.0.4 (2021-02-15)
#Platform: x86_64-pc-linux-gnu (64-bit)
#Running under: Ubuntu 20.04.2 LTS
#
#Matrix products: default
#BLAS:   /usr/lib/x86_64-linux-gnu/blas/libblas.so.3.9.0
#LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.9.0
#
#locale:
# [1] LC_CTYPE=pt_PT.UTF-8       LC_NUMERIC=C              
# [3] LC_TIME=pt_PT.UTF-8        LC_COLLATE=pt_PT.UTF-8    
# [5] LC_MONETARY=pt_PT.UTF-8    LC_MESSAGES=pt_PT.UTF-8   
# [7] LC_PAPER=pt_PT.UTF-8       LC_NAME=C                 
# [9] LC_ADDRESS=C               LC_TELEPHONE=C            
#[11] LC_MEASUREMENT=pt_PT.UTF-8 LC_IDENTIFICATION=C       

#attached base packages:
#[1] stats     graphics  grDevices utils     datasets  methods   base     
#
#loaded via a namespace (and not attached):
#[1] compiler_4.0.4