promise already under evaluation: recursive default argument reference or earlier problems?

Formal arguments of the form x=x cause this. Eliminating the two instances where they occur we get the following. (The reason you can’t use x=x in the formal arguments of a function definition is that it first looks up the default argument within the function itself so using that form is telling it to use itself as the default but it has not been defined so that makes no sense and we get an error.)

f <- function(x, T) {
   10 * sin(0.3 * x) * sin(1.3 * x^2) + 0.001 * x^3 + 0.2 * x + 80 
}

g <- function(x, T, f. = f) {  ## 1. note f.
   exp(-f.(x)/T) 
}
 
test<- function(g. = g, T = 1) {  ## 2. note g.
   g.(1,T) 
}
 
test()
## [1] 8.560335e-37

Leave a Comment