title: How to pass function arguments when creating a list of tasks in R?
body: <p>I'm trying to create a list of tasks to run in R parallel using mclapply.</p>
  
  <pre><code>library(parallel)
  tasks &lt;- list(
    job1 = y(5),
    job2 = y(6)
  
  )
  
  # Using fork()
  out &lt;- mclapply( 
    tasks, 
    function(f) f(), 
    mc.cores = length(tasks) 
  )
  </code></pre>
  
  <p>where y is for example:</p>
  
  <pre><code>y&lt;-function(x){
  a&lt;-x^2
  return(a)    
  }
  </code></pre>
  
  <p>When creating the list, it executes the functions with arguments instead of only storing it as a list. (So this is before even arriving at the actual <code>mclapply</code>.)
  If I use a function <code>y</code> without any arguments, this approach runs fine:</p>
  
  <pre><code>tasks &lt;- list(
    job1 = y,
    job2 = y
  
  )
  
  # Using fork()
  out &lt;- mclapply( 
    tasks, 
    function(f) f(), 
    mc.cores = length(tasks) 
  )
  </code></pre>
  
  <p>where y is for example:</p>
  
  <pre><code>y&lt;-function(){
  a&lt;-5^2
  return(a)    
  }
  </code></pre>
  
  <p>So how do I store the functions <em>with arguments</em> in a list without executing the functions (until I tell them to in mclapply)?</p>