-
-
Notifications
You must be signed in to change notification settings - Fork 878
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
Valid use cases for error=TRUE, include=FALSE
#1914
Comments
Maybe you can workaround with knitr::ops_chunk$set(error = TRUE, echo = FALSE, results = 'hide', fig.show = 'hide') |
This is not sufficient as the error message will still be printed in the document. |
You are right. Then, this: knitr::opts_chunk$set(error = TRUE,
echo = FALSE,
results = 'hide',
fig.show = 'hide',
message = FALSE,
warning = FALSE)
knitr::knit_hooks$set(
error = function(...) NULL
) |
Oh, if you include nothing and accept error, you do not even have to evaluate. knitr::opts_chunk$set(eval = FALSE, echo = FALSE) |
@atusy's first solution could solve the problem when you need to evaluate the previous code chunks; the section solution works when you don't need to evaluate them. That said, I just added support for |
This old thread has been automatically locked. If you think you have found something related to this, please open a new issue by following the issue guide (https://yihui.org/issue/), and link to this old issue if necessary. |
By filing an issue to this repo, I promise that
xfun::session_info('knitr')
. I have upgraded all my packages to their latest versions (e.g., R, RStudio, and R packages), and also tried the development version:remotes::install_github('yihui/knitr')
.I understand that my issue may be closed if I don't fulfill my promises.
The current implementation of knitr enforces a stop on first error evaluation when
include=FALSE
regardless of theerror
option's value.knitr/R/block.R
Lines 188 to 194 in 0a77ac2
I understand why this was chosen and why this makes sense as default behavior for most use cases, however I think there needs to be some way to override this in certain circumstances.
Specifically, I currently have a use case where I am taking student submitted Rmd documents and I am attempting to output and highlight a small section of the overall document. Since there is not an effective way of determining dependence between chunks, my brute force approach involves setting all preceding chunks to
include=FALSE
and knitting. This works as expected if none of the chunks have errors, however if any of the previous chunks do have an error, even if this has no bearing on the chunk of interest's ability to run, the knit fails. As such, I would like to be able to useerror=TRUE
in this circumstance and allow everything to run regardless of any errors along the way but this is not currently possible.I've experimented extensively with trying to achieve the same effect with error hooks and options but this ends up being both clunky and not 100% effective (lingering markdown code blocks). My current solution involves just wrapping the code in each chunk with
try()
but this is also not idea as it has slightly different behavior fromerror=TRUE
with the chunk stoping execution after the first error.I don't know what a prefered solution would look like for you, but it seems like something as simple as adding a new option that modifies this behavior could make this possible. Maybe something like
error.allow
.The text was updated successfully, but these errors were encountered: