Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rmarkdown - Run code and display errors in document

I get an error message when running the code below which is expected - I would like this to be ran and displayed in the pdf, however the error is returned in r and the code doesn't run.

{r, warning=TRUE} library(survey) debug(withReplicates.svyrep.design)

I have tried warning=TRUE but this doesn't work.

How can I get the error displayed in the document?

like image 789
dpel Avatar asked Dec 07 '15 15:12

dpel


People also ask

How do you display output but hide code in R Markdown?

Chunk options The initial line in a code chunk may include various options. For example, echo=FALSE indicates that the code will not be shown in the final document (though any results/output would still be displayed). You use results="hide" to hide the results/output (but here the code would still be displayed).

How do you show results in R Markdown?

There are two ways to render an R Markdown document into its final output format. If you are using RStudio, then the “Knit” button (Ctrl+Shift+K) will render the document and display a preview of it. Note that both methods use the same mechanism; RStudio's “Knit” button calls rmarkdown::render() under the hood.

How do I embed code into R Markdown?

You can insert an R code chunk either using the RStudio toolbar (the Insert button) or the keyboard shortcut Ctrl + Alt + I ( Cmd + Option + I on macOS).


1 Answers

Add error=TRUE to the chunk options. That will result in the script running to completion with the error appearing in the output.

like image 180
eipi10 Avatar answered Oct 23 '22 18:10

eipi10