0

I am attempting to call a system command from within an R script. The system command I want to call is a name of a software that I load as a module on a shared computing cluster (using singularity). The problem I am having is that the software is not able to run when I use the system command.

system_trial.R) has only one line:

system('STAR')

hostname[1] Rscript system_trial.R
sh: STAR: command not found
Warning message:
In system("STAR") : error in running command

Of course, the software works if I call it from the shell directly.

hostname[2] STAR
Usage: STAR  [options]... --genomeDir /path/to/genome/index/   --readFilesIn R1.fq R2.fq
Spliced Transcripts Alignment to a Reference (c) Alexander Dobin, 2009-2020
  • If I run which STAR, I get singularity exec /apps/singularity-3/star/star-2.7.5a--0.sif STAR $@

  • Replacing system('STAR') with system('singularity exec /apps/singularity-3/star/star-2.7.5a--0.sif STAR $@') actually executes the software.

  • Replacing system('STAR') with system('which STAR'), returns which: no STAR in (/bin:etc...)

  • Using system2('STAR') gives sh: STAR: command not found.

I would like to simply use system('STAR'). How can I achieve this?

Related post without an answer: R: calling a system command

iich
  • 145
  • 1
  • 8
  • Have you tried [`system2`](https://stat.ethz.ch/R-manual/R-devel/library/base/html/system2.html)? – Rui Barradas Oct 12 '20 at 21:15
  • How about system("$(which STAR)")? It's close to your third option, but invokes a shell within the command to evaluate and return `which STAR`. – Jay Achar Oct 13 '20 at 12:04
  • @JayAchar, this did not work either. – iich Oct 14 '20 at 15:06
  • Have you compared running `system("echo $PATH")` with running `echo $PATH` from terminal? – David Oct 14 '20 at 15:50
  • Also, maybe look into `.bashrc` or similar (I have no experience with singularity) if there is a link from `STAR` to `singularity exec ....` if so, I think R's `system()` doesn't source `.bashrc` et al. which would mean you have to either source it by hand or create the reference otherwise. – David Oct 14 '20 at 15:52
  • @iich, did you ever resolve the issue here? A recent question: https://stackoverflow.com/q/76905897/3358272 that might be similar (the `system(.)` call is erring on a cluster node). – r2evans Aug 16 '23 at 12:41

0 Answers0