title: Passing value to a function through R CMD BATCH
body: <p>I have a function created in R for test purpose that will get two values, add them and assign the result to a variable and the result will be stored  in a csv file. Below is my r code</p>
  
  <pre><code>  f2 &lt;- function(x, y) {
    args=(commandArgs(TRUE))
    z1 &lt;- x + y
    z2 &lt;- x + 2*y
    b &lt;- list(z1, z2) 
    write.csv(b,"testfun.csv",row.names=F)
    print(z1)
    print(z2)
    print(b)
  }
  </code></pre>
  
  <p>The code is working fine and i am able to pass the values to my function through r console. However I want to do this using R CMD and not in a r console. This is because i have a web application that will invoke this function on click of a button.</p>
  
  <p>I tried to invoke the function using the below code</p>
  
  <pre><code>Rscript test.R 5 100
  </code></pre>
  
  <p>and </p>
  
  <pre><code>R CMD BATCH --no-save --no-restore '--args x=3 y=5' test.R test.out &amp;
  </code></pre>
  
  <p>However the function is not getting invoked and i am not getting the output. When i run the above R CMD BATCH statement i'm getting an error like ''--args'' no such file or directory. </p>
  
  <blockquote>
    <p>Fatal error: cannot open file ''--args': No such file or directory</p>
  </blockquote>
  
  <p>So i moved the  '--args x=3 y=5' values after the test.R something like</p>
  
  <pre><code>R CMD BATCH --no-save --no-restore test.R '--args x=3 y=5' test.out &amp;
  </code></pre>
  
  <p>On executing the above i'm getting my r sript saved in the directory and not the my expected output. I tried all the ways from the below link</p>
  
  <p><a href="https://stackoverflow.com/questions/14167178/passing-command-line-arguments-to-r-cmd-batch">Passing command line arguments to R CMD BATCH</a></p>
  
  <p>Can anyone shed some light over this? I need to invoke my function along with some parameter through rscript or r cmd.</p>