I'm trying to write a document that discusses using errors to communicate problems with the arguments to the user. Unfortunately, I can't seem to get the .Rmd file to knit. A short example:
Intro text
```{r}
some_function <- function(x, y)
{
if (x < 0) stop("x must be greater than 0")
x + y
}
some_function(3, 2)
```
```{r}
some_function(-3, 2)
```
When I try to knit this to any format, I get the error
Quitting from lines 14-15 (test.Rmd)
Error in some_function(-3, 2) : x < 0
Calls: <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval -> some_function
Execution halted
Everything I've read so far points to this being a problem with either a) not loading a package, or b) an incorrectly set path in the Rmd file.
Since I'm only using base functions here and am not referencing any files (that I'm aware of, anyway), I don't think either of those are my problem (but I'll be happy to be wrong).
Any tips on what I need to do to get the document to knit?
Solution
Add the following to the top of the .Rmd
```{r, echo=FALSE}
knitr::opts_chunk$set(error = TRUE)
```
Short explanation, RMarkdown v1 used error = TRUE
by default, but RMarkdown v2 uses error = FALSE
. See the link in Josh's comment below.
Don't compile with the button in rstudio. Try:
library("knitr")
knit2html("file")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With