title: Finding derivate of function in R
body: <p>I am using R and trying to make an function by giving 2 parameters which are function and x, try to look for the answer of the function. But I kept getting error. I do not want to use any packages just solely R base. 
  Heres the Code so far.</p>
  
  <pre><code>test2 &lt;- function(x) {
    func &lt;- expression(x)
    der&lt;- D(eval(func), 'x')
    return(der(x))
  }
  test2(function(x) return(x^2))
  </code></pre>
  
  <p>I kept getting this error: "expression must not be type 'closure'"
  Is there any way that I can structure of the function?</p>