JVGen
March 2, 2021, 4:02pm
1
I have an R Markdown file that I repurpose to analyze new samples. Sometimes the analysis generates no significant results, and so when I try to plot the result an error is thrown. I simply want to continue to Knit the html file if such an error occurs.
I've tried {r error = TRUE}
, but the knitting still halts for some reason. Is there another knitr option that would bypass the error?
{r Gene Ontology Enrichment, error = TRUE}
enrichplot::barplot(ego.MF,
font.size = 8,
title="GO Enrichment - Molecular Function",
showCategory=20)
Quitting from lines 441-478 (file.Rmd)
Error in ans[ypos] <- rep(yes, length.out = len)[ypos] :
replacement has length zero
This is also posted on Stack Overflow , but hasn't gotten any responses.
cderv
March 2, 2021, 6:05pm
2
error = TRUE
should catch the error and show it in the Rmd output and not exit the rendering process.
Do you have a full example to share ?
You could also make the plot chunk conditional using a condition for eval =
involving a previous result.
If FALSE, the chunk would not be evaluated.
JVGen
March 2, 2021, 7:23pm
3
In creating a simplified version for you to view, I believe I found the issue. The section causing the issue had the header:
{r Gene Ontology Enrichment, include = FALSE, error = TRUE}
Quitting from lines 88-104 (example.Rmd)
Error in ans[ypos] <- rep(yes, length.out = len)[ypos] :
replacement has length zero
Calls: <Anonymous> ... expand_limits_discrete_trans -> expand_limits_continuous_trans -> ifelse
Execution halted
Removing include=FALSE
allows knitting to continue. However, I am now left with a chunk of code that I would rather not display in the report.
Any ideas how I can both exclude this section from the report and bypass stops due to errors?
cderv
March 2, 2021, 7:39pm
4
Yeah if you said include to FALSE, error will always stop
See documentation of the option Options - Chunk options and package options - Yihui Xie | 谢益辉
If you want to hide the code source you can set echo=FALSE
.
JVGen
March 2, 2021, 8:04pm
5
Thank you. I accepted your response as a Solution - is there anything more I should do to 'close' the thread?
1 Like
cderv
March 2, 2021, 9:21pm
6
That is how you close a thread !
system
Closed
March 9, 2021, 9:21pm
7
This topic was automatically closed 7 days after the last reply. New replies are no longer allowed. If you have a query related to it or one of the replies, start a new topic and refer back with a link.