Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUGZILLA #17831] numericDeriv alters result of eval #7007

Open
github-actions bot opened this issue Jun 17, 2020 · 0 comments
Open

[BUGZILLA #17831] numericDeriv alters result of eval #7007

github-actions bot opened this issue Jun 17, 2020 · 0 comments

Comments

@github-actions
Copy link

Reported by Raimundo Neto on R-devel 2020-06-15.

Simple example that fails:

 x <- 0
 tryCatch(numericDeriv(quote(sqrt(-x)), "x"), error = identity)
 stopifnot(x == 0)

We save and restore the theta value but don't guard against a jump.
We could put in a cleanup handler at the C level.

Cleaner is probably to push another frame with the variable to change
on the environment. At the R level this can be done in numericDeriv by
changing

val <- .Call(C_numeric_deriv, expr, theta, rho, dir)

to

rho1 <- new.env(parent = rho)
assign(theta, get(theta, rho), rho1)
val <- .Call(C_numeric_deriv, expr, theta, rho1, dir)

Might be better to make the analogous change at C level though as we
document numeric_deriv in R-exts.texi.


METADATA

  • Bug author - Luke Tierney
  • Creation time - 2020-06-16 14:27:28 UTC
  • Bugzilla link
  • Status - NEW
  • Alias - None
  • Component - Low-level
  • Version - R 4.0.x
  • Hardware - All All
  • Importance - P5 normal
  • Assignee - R-core
  • URL -
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

0 participants