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

Marc Girondot marc_grt at yahoo.fr
Fri Nov 16 12:02:35 CET 2012


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



More information about the R-help mailing list