evaluate
evaluate copied to clipboard
`on.exit()` not captured inside of a function
f <- function() {
cat("Hello\n")
on.exit(cat("Bye\n"))
stop("Error")
}
evaluate::evaluate("f()")
#> <evaluation>
#> Source code:
#> f()
#> Text output:
#> Hello
#> Condition:
#> Error in f():
#> Error
Created on 2025-08-04 with reprex v2.1.1
This is also present in quarto and rmarkdown see: https://github.com/quarto-dev/quarto/issues/796#issuecomment-3300185465
in a .qmd (quarto render error.qmd):
---
format: html
---
```{r}
#| error: true
f <- function() {
cat("Hello\n")
on.exit(cat("Bye\n"))
stop("Error")
}
f()
```
return:
Hello
Error in f(): Error
In a .rmd
---
output: html_document
---
```{r}
#| error: true
f <- function() {
cat("Hello\n")
on.exit(cat("Bye\n"))
stop("Error")
}
f()
```
Will return the same:
Hello
Error in f(): Error
Thanks for additional info.
To confirm: knitr uses evaluate, rmarkdown uses knitr so it will be affected. Same as quarto which will use knitr under the hood when engine: knitr is the one active.