title: Calling external program from R with multiple commands in system
body: <p>I am new to programming and mainly I am able to do some scripts within R, but for my work I need to call an external program. For this program to work on the ubuntu's terminal I have to first use setenv and then execute the program. Googling I've found the system () and Sys.setenv() functions, but unfortunately I can make it function.</p>
  
  <p>This is the code that does work in the ubuntu terminal:</p>
  
  <pre><code>$ export PATH=/home/meme/bin:$PATH
  $ mast "/home/meme/meme.txt" "/home/meme/seqs.txt" -o "/home/meme/output" -comp
  </code></pre>
  
  <p>Where the first two arguments are input files, the -o argument is the output directory and the -comp is another parameter for the program to run.</p>
  
  <p>The reason that I need to do it in R despite it already works in the terminal is because I need to run the program 1000 times with 1000 different files so I want to make a for loop where the input name changes in every loop and then analyze every output in R.</p>
  
  <p>I have already tried to use:</p>
  
  <pre><code>Sys.setenv(PATH="/home/meme/bin"); system(mast "/home/meme/meme.txt" "/home/meme/seqs.txt" -o "/home/meme/output" -comp )
  </code></pre>
  
  <p>and</p>
  
  <pre><code>system(Sys.setenv(PATH="/home/meme/bin") &amp;&amp; mast "/home/meme/meme.txt" "/home/meme/seqs.txt" -o "/home/meme/output" -comp )
  </code></pre>
  
  <p>but always received:</p>
  
  <pre><code>Error: unexpected constant string in "system(mast "/home/meme/meme.txt""
  </code></pre>
  
  <p>or</p>
  
  <pre><code>Error: unexpected symbol in "system(Sys.setenv(PATH="/home/meme/bin") &amp;&amp; mast "/home/meme/meme.txt""
  </code></pre>
  
  <p>At this point I have run out of ideas to make this work. If this has already been answered, then my googling have just been poor and I would appreciate any links to its response.</p>
  
  <p>Thank you very much for your time.</p>
  
  <p>Carlos</p>
  
  <p>Additional details:</p>
  
  <p>I use Ubuntu 12.04 64-bits version, RStudio version 0.97.551, R version 3.0.2 (2013-09-25) -- "Frisbee Sailing" Platform: x86_64-pc-linux-gnu (64-bit).
  The program I use (MAST) finds a sequence pattern in a list of letters and is part of the MEME SUIT version 4.9.1 found in <a href="http://meme.nbcr.net/meme/doc/meme-install.html" rel="noreferrer">http://meme.nbcr.net/meme/doc/meme-install.html</a> and run through command line. The command-line usage for mast is:</p>
  
  <pre><code>mast    &lt;motif file&gt; &lt;sequence file&gt; [options]
  </code></pre>