title: Run a function multiple times with different arguments each run
body: <p>I am trying to run a function multiple times using different arguments for each run. The arguments are called by a sub function and the output of the sub function is then used in the main function. I have been trying to do it using <code>mapply</code> but am not having any luck..</p>
  
  <p>Pseudo-code of what I am trying to do:</p>
  
  <p>Create a df of 8 different possible argument combinations to use in the function:</p>
  
  <pre><code>a &lt;- 1:2
  b &lt;- 1:2
  c &lt;- 1:2
  my.args &lt;- expand.grid(a = a, b = b, c = c)
  
  head(my.args)
    a b c
  1 1 1 1
  2 2 1 1
  3 1 2 1
  4 2 2 1
  5 1 1 2
  </code></pre>
  
  <p>Create the function</p>
  
  <pre><code>my.func &lt;- function(a,b,c) {
      my.sub.func &lt;- function(bits = c(0,1,2), times = 1) {
      sample(bits, times, prob = c(a,b,c), replace = TRUE)
      }
   #..... do a bunch of stuff using my.sub.func()
  
  }
  </code></pre>
  
  <p>run the function using each each row of <code>my.args</code> as the input arguments</p>
  
  <pre><code>mapply (my.func, a = my.args[,1], b = my.args[,2], c = my.args[,3])
  </code></pre>
  
  <p>This does not work, I think the issue has something to do with the structure of <code>prob = c(a,b,c)</code> in <code>my.sub.func()</code></p>