It used to be possible to get an informative traceback when rendering R Markdown non-interactively, where the traceback would only show function calls for code within the R Markdown notebook, as long as the notebook contained this code from the Debugging chapter:
However, this behavior seems to have gone away with newer versions of R, knitr, rmarkdown, and rlang, and instead the traceback contains numerous knitr & rmarkdown function calls but nothing from the R Markdown source file itself.
example
Here's a simple notebook.Rmd that uses the above code and throws an error:
Rendered from a terminal with:
```sh
R -e "rmarkdown::render('notebook.Rmd')"
where the global error option is NULL:
getOption('error')
NULL
older versions
With older versions:
R: 4.1.0
rmarkdown: 2.9
knitr: 1.33
rlang: 0.4.11
The output is helpful, only showing code from the R Markdown file in the traceback:
processing file: notebook.Rmd
|.................. | 25%
ordinary text without R code
|................................... | 50%
label: setup
|.................................................... | 75%
ordinary text without R code
|......................................................................| 100%
label: error
to_error: TRUE ( logical )
Quitting from lines 19-27 (notebook.Rmd)
Error in func(to_error) : ERROR
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> throw_error -> func
█
1. └─global::throw_error(params$to_error)
2. └─global::func(to_error)
3. └─base::stop("ERROR")
Warning message:
In sink() : no sink to remove
newer versions
But with newer versions:
R: 4.4.1
rmarkdown: 2.28
knitr: 1.48
rlang: 1.1.4
The output is extremely verbose and includes rmarkdown & knitr calls in the stack, but crucially doesn't include underlying code from the R Markdown file.
Did something regress in one or some of these newer package versions? Or am I overlooking something about the R environment? How can I get a traceback showing only code from the R Markdown file, but using these newer versions of R, rmarkdown, knitr, and rlang?
It used to be possible to get an informative traceback when rendering R Markdown non-interactively, where the traceback would only show function calls for code within the R Markdown notebook, as long as the notebook contained this code from the Debugging chapter:
However, this behavior seems to have gone away with newer versions of R, knitr, rmarkdown, and rlang, and instead the traceback contains numerous knitr & rmarkdown function calls but nothing from the R Markdown source file itself.
example
Here's a simple
notebook.Rmd
that uses the above code and throws an error:where the global error option is
NULL
:older versions
With older versions:
The output is helpful, only showing code from the R Markdown file in the traceback:
newer versions
But with newer versions:
The output is extremely verbose and includes rmarkdown & knitr calls in the stack, but crucially doesn't include underlying code from the R Markdown file.
Did something regress in one or some of these newer package versions? Or am I overlooking something about the R environment? How can I get a traceback showing only code from the R Markdown file, but using these newer versions of R, rmarkdown, knitr, and rlang?