title: R - " cannot coerce type 'closure' to vector of type 'any' " when using outer(x, f) function
body: <p>I'm trying plot a 3D perspective of a function, but I'm getting this error when I use <code>z &lt;- outer(x, egg)</code></p>
  
  <pre><code>Error in as.vector(x, mode) : 
    cannot coerce type 'closure' to vector of type 'any'
  </code></pre>
  
  <p>My script:</p>
  
  <pre><code>egg &lt;- function(x) {
    return (-(x[2] + 47)*sin(sqrt(abs((x[1]/2) + x[2] + 47))) - x[1]*sin(sqrt(abs(x[1] - (x[2] + 47)))))
  }
  
  # Plotting eggholder
  x1 &lt;- seq(-512, 512, length.out=100)
  x2 &lt;- seq(-512, 512, length.out=100)
  x &lt;- c(x1, x2)
  z &lt;- outer(x, egg)
  par(mar=c(1,1,1,1))
  layout(matrix(1:4, nrow=2))
  lapply(c(0,30,60,90), function(t) persp(x1,x2,z, col='blue', theta=t))
  </code></pre>