0

I'm writing a method for the class "function" in R

fct.function <- function(x, start, tolerance = 1e-7, niter = 500)

This method needs a numerical approximatimation of the derivative of the function x. For this I want to use numericDev. Now

abl1 <- numericDeriv(quote(x),theta="lambda")

doesn't work because R cannot coerce the type 'closure' to a vector of type 'double'. Do you have any idea to fix that?

Here is some code:

# R version 3.3.1 on Windows 10
fct.function <- function(x, start=0, tolerance = 1e-7, niter = 500){
abl1 <- numericDeriv(quote(x),theta="lambda") # supposing that the function x is a function of lambda 
abl2 <- numericDeriv(quote(abl1),theta="lambda")
}

For example this leads to an error:

x<-function(lambda) lambda^2
fct(x)

Thank you!

Sofia
  • 67
  • 1
  • 7
  • It would be easier to help if you provided some sort of [reproducible example](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) – MrFlick May 16 '17 at 21:50
  • @MrFlick Is it clearer for you now? Do you have any idea? – Sofia May 17 '17 at 20:21
  • what is the value that you are passing to x? what is the class of the object being passed? – tushaR May 19 '17 at 08:35
  • @Tushar In my example the class of the object I am passing is "function" and the value is "function(lambda) lambda^2". I think the problem is that "quote(x)" gives exactly "function(lambda) lambda^2" but I need "lambda^2". – Sofia May 21 '17 at 09:57

0 Answers0