. Advertisement .
..3..
. Advertisement .
..4..
I encountered the following problem in completing my work:
> test()
Error in test() :
promise already under evaluation: recursive default argument reference or earlier problems?
Below is the code I ran:
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) {
exp(-f(x) / T)
}
test <- function(g=g, T=1) {
g(1, T)
}
What’s causing it, and how can it be resolved in the “promise already under evaluation: recursive default argument reference or earlier problems“ in the r?
The cause: This is caused by formal arguments of the type x=x. We obtain the following when we take out the two instances where they appear. (You can’t use x=x in the formal arguments of a function declaration because it first searches up the default parameter within the function; using that form would be instructing it to use itself as the default, but because it hasn’t been defined, it wouldn’t make sense, and we would receive an error.)
Solution: Try this code to fix the promise already under evaluation: recursive default argument reference or earlier problems:
You can avoid the problem of the same name by especifying argument evaluation context