Can't resolve error in .Rmd file <Anonymous> … withCallingHandlers -> withVisible -> eval -> eval ->

我只是一个虾纸丫 提交于 2019-12-07 02:38:31

问题


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.


回答1:


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

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


来源:https://stackoverflow.com/questions/30519673/cant-resolve-error-in-rmd-file-anonymous-withcallinghandlers-withvisi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!