[R] Derivative of a Function Expression

Gabor Grothendieck ggrothendieck at gmail.com
Tue Sep 4 01:29:54 CEST 2007


One improvement.  This returns a function directly without having
to create a template and filling in its body:

deriv(body(f), "x", func = TRUE)

On 9/3/07, Gabor Grothendieck <ggrothendieck at gmail.com> wrote:
> The problem is that brace brackets are not in the derivatives table.
> Make sure you don't have any.
>
> On 9/3/07, Alberto Vieira Ferreira Monteiro <albmont at centroin.com.br> wrote:
> > Gabor Grothendieck wrote:
> > >
> > > Actually in thinking about this its pretty easy to do it without Ryacas
> > > too:
> > >
> > > Df <- f
> > > body(Df) <- deriv(body(f), "x")
> > > Df
> > >
> > This is weird.
> >
> > f <- function(x) { x^2 + 2*x+1 }
> > Df <- f
> > body(Df) <- deriv(body(f), "x") # error
> >
> > Also:
> >
> > f <- function(x) x^2 + 2 * x + 1
> > Df <- f
> > body(Df) <- deriv(body(f), "x") # ok
> > D2f <- f
> > body(D2f) <- deriv(body(Df), "x") # error
> >
> > Alberto Monteiro
> >
>



More information about the R-help mailing list