Calling an external program from R with several commands in the system

I am new to programming and basically I can execute some scripts inside R, but for my work I need to call an external program. For this program to work on the ubuntu terminal, I must first use setenv and then execute the program. Googling I found the functions system () and Sys.setenv (), but unfortunately I can make it function.

This is the code that runs on the ubuntu terminal:

$ export PATH=/home/meme/bin:$PATH
$ mast "/home/meme/meme.txt" "/home/meme/seqs.txt" -o "/home/meme/output" -comp

If the first two arguments are input files, the -o argument is the output directory, and -comp is another option to run the program.

The reason I need to do this in R, even though it already works in the terminal, is because I need to run the program 1000 times with 1000 different files, so I want to create a for loop in which the input name changes in each cycle and then analyze each output in R.

I already tried to use:

Sys.setenv(PATH="/home/meme/bin"); system(mast "/home/meme/meme.txt" "/home/meme/seqs.txt" -o "/home/meme/output" -comp )

and

system(Sys.setenv(PATH="/home/meme/bin") && mast "/home/meme/meme.txt" "/home/meme/seqs.txt" -o "/home/meme/output" -comp )

but always accepted:

Error: unexpected constant string in "system(mast "/home/meme/meme.txt""

or

Error: unexpected symbol in "system(Sys.setenv(PATH="/home/meme/bin") && mast "/home/meme/meme.txt""

At this point, I'm running out of ideas to do this job. If this had already been answered, my googling was simply poor, and I would appreciate any links to his answer.

Thanks so much for your time.

Carlos

Additional Information:

64- Ubuntu 12.04, RStudio 0.97.551, R 3.0.2 (2013-09-25) - "Frisbee Sailing": x86_64-pc-linux-gnu (64- ), , (MAST), MEME SUIT 4.9.1, http://meme.nbcr.net/meme/doc/meme-install.html . :

mast    <motif file> <sequence file> [options]
+4
1

, paste, system:

for(i in 1:10){
cmd=paste("export FOO=",i," ; echo \"$FOO\" ",sep='')
system(cmd)
}

sep='' paste .

print(cmd) system(cmd), , . :

if(TESTING){print(cmd)}else{system(cmd)}

TESTING=TRUE FALSE R .

system, , script , R. - :

cmd = paste("/home/me/bin/dojob.sh ",i,i+1)
system(cmd)

dojob.sh script, . .

+9

All Articles