title: R - Pass element of list as argument to function call
body: <p>Let's start with some simple code:</p>
  
  <pre><code>require(randomForest)
  randomForest(mpg~.,mtcars,ntree=10)
  </code></pre>
  
  <p>This builds a random forest of 10 trees.</p>
  
  <p>What I want is to store the parameter in a list in than make the function call. Something like this:</p>
  
  <pre><code>require(randomForest)
  l&lt;-list(ntree=10)
  randomForest(mpg~.,mtcars,l[[1]])
  </code></pre>
  
  <p>However, this does not work. The error message is:</p>
  
  <pre><code>Error in if (ncol(x) != ncol(xtest)) stop("x and xtest must have same number of columns") : argument is of length zero
  </code></pre>
  
  <p>This indicates that the parameter xtest=NULL of randomForest is set to 10 instead of ntree. </p>
  
  <p>Why is that? How can I pass the parameter ntree as a list element?</p>
  
  <p>Thank you.</p>