[Rd] numericDeriv alters result of eval in R 4.0.1

Raimundo Neto r@|mundonetto1 @end|ng |rom gm@||@com
Mon Jun 15 17:37:11 CEST 2020

Dear R developers,

I've run into a weird behavior of the numericDeriv function (from the stats
package) which I also posted on StackOverflow (question has same title as
this email, except for the version of R).

Running the code bellow we can see that the numericDeriv function gives an
error as the derivative of x^a wrt a is x^a * log(x) and log is not defined
for negative numbers. However, seems like the function changes the value of
env1$a from 3 to 3.000000044703483581543. If x is a vector of positive
values numericDeriv function completes the task without errors  and env1$a
remains unchanged as expected.

This happened to me running R 4.0.1 on Ubuntu 20.04 and also to another
StackOverflow user using running the same version of R on Windows 10. I
wonder, is this an intended behavior of the function or really a bug?

env1 = new.env()
env1$x = rnorm(10)
env1$a = 3
eval(quote(x^a), env1)
numericDeriv(quote(x^a), "a", env1)
eval(quote(x^a), env1)

Thank you!
Raimundo Neto

	[[alternative HTML version deleted]]

More information about the R-devel mailing list