title: (Optim) Error: (list) object cannot be coerced to type 'double'
body: <p>In a larger optimization task, i'm stuck at a point where I need to input a list into <code>optim</code>. However, when within the list there is a vector, I get the error</p>
  
  <p>(list) object cannot be coerced to type 'double'</p>
  
  <p>Below there's an reproducible example and the error source is in the <code>butter</code> line. Splitting it into scalars makes the code work, but what I really want to is a list like <code>init_param</code> (with <code>butter</code> being a vector).</p>
  
  <pre><code>fun = function(param_list){
  
    x2 = param_list[["x2"]]
    bread = param_list[["bread"]]
    x3 = param_list[["x3"]]
    butter = param_list[["butter"]]
  
    sum(
      (bread - 3)^2, (x2-4)^2, (x3-125)^2, (butter[1])^2, (butter[2])^2
      )
  }
  
  init_param = list(x3 = -1, bread = 50, x2 = 120, butter = c(1,2))
  
  optim(par = init_param, fn = fun)
  
  </code></pre>