[R] How to get the result of eval()

Rui Barradas ruipbarradas at sapo.pt
Fri Nov 16 15:04:12 CET 2012


Hello,
Try the following.

attr(eval(dx2x), "gradient")

Hope this helps,

Rui Barradas
Em 16-11-2012 11:02, Marc Girondot escreveu:
> I just discover the deriv function but I have a minor problem at the 
> end when using its result:
> For example:
>
> dx2x <- deriv(~ A*x^2, "x") ; dx2x
>
> # it works fine:
> # expression({
> # .value <- A * x^2
> # .grad <- array(0, c(length(.value), 1L), list(NULL, c("x")))
> # .grad[, "x"] <- A * (2 * x)
> # attr(.value, "gradient") <- .grad
> # .value
> # })
>
> A <- 3
> x <- 23
>
> eval(dx2x)
>
> # great 138 is well the derivative at the point 23
> # [1] 1587
> # attr(,"gradient")
> # x
> # [1,] 138
>
>
> But I don’t know how to get the 138 value.
>
> Any idea ?
>
> Thanks a lot
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide 
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list