Ben
Ben

Reputation: 519

Stop on error when executing Rmarkdown chunk

I'm using RStudio 1.4 and R 3.6.3. When I execute a single code chunk in a Rmarkdown document (ie I press "Run Current Chunk", or use the Ctrl+Shift+Enter shortcut) it does not stop on errors. Is it possible to make it stop?

For instance, if I run the following chunk in an otherwise empty rmd file:

```{r, error=TRUE}
stop()
print("A")
```

I get the following output in the RStudio console:

> stop()
Error: 
> print("A")
[1] "A"

I get the same thing if error = FALSE. However, I noticed that having the chunk send output inline makes it stop on the error (but I usually work with output to the console). So it seems to be a RStudio issue, despite the fact that Phil removed that information from the question's title and tags earlier.

Upvotes: 2

Views: 915

Answers (1)

Joel Beck
Joel Beck

Reputation: 398

As documented on page 2 of the R Markdown Reference CheatSheet the chunk option error=TRUE only effects the output of the knitted document, i.e. it determines whether the knitting process stops on code errors or continues by showing the error message in the output document.

When running code chunks within the R Markdown document, all lines are executed and I am not aware of any option to change this behaviour.

Upvotes: 1

Related Questions