Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot run program using system() in R

I am trying to run computeMatrix from the package deepTools in a R script using system().

The following command gets this error message.

system('computeMatrix --help')

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

However, if I run the same command in the terminal everthing works fine.


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

like image 934
samu Avatar asked Dec 28 '25 16:12

samu


1 Answers

This was run in Ubuntu 20.04.
The recommended way of running system commands is with system2, not system. The arguments are passed in a vector, args. In this case args is a length 1 vector but if there are more than one argument, pass them as

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

This command worked as expected.

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
like image 50
Rui Barradas Avatar answered Dec 31 '25 18:12

Rui Barradas



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!