Unable to resolve error in .Rmd file <Anonymous> ... withCallingHandlers & # 8594; withVisible & # 8594; eval & # 8594; eval ->

I am trying to write a document that discusses using errors to pass argument problems to the user. Unfortunately I cannot 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 link 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 indicates that this is a problem: either not downloading the package, or b) incorrectly set path in the Rmd file.

Since I'm only using basic functionality and not linking to any files (which I know, anyway), I don't think this is one of my problems (but I'll be happy to be wrong).

Any tips on what I need to do to get a paper knit?

Decision

Add the following to the beginning of the .Rmd

```{r, echo=FALSE}
knitr::opts_chunk$set(error = TRUE)
```

      

Short explanation, RMarkdown v1 is used by default error = TRUE

, but RMarkdown v2 is using error = FALSE

. See Link in Josh's comment below.

+3


source share


1 answer


Don't compile with a button in rstudio. Try:



library("knitr")
knit2html("file")

      

+2


source







All Articles