无法解决 .Rmd 文件中的错误 <Anonymous>... withCallingHandlers ->withVisible ->评估 ->评估 -> [英] Can't resolve error in .Rmd file <Anonymous> ... withCallingHandlers -> withVisible -> eval -> eval ->

查看:169
本文介绍了无法解决 .Rmd 文件中的错误 <Anonymous>... withCallingHandlers ->withVisible ->评估 ->评估 ->的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试编写一个文档,讨论使用错误向用户传达参数问题.不幸的是,我似乎无法编织 .Rmd 文件.一个简短的例子:

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

到目前为止我读到的所有内容都表明这是一个问题,原因是 a) 没有加载包,或者 b) Rmd 文件中的路径设置不正确.

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?

解决方案

在.Rmd的顶部添加以下内容

Add the following to the top of the .Rmd

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

简短说明,RMarkdown v1 默认使用error = TRUE,但RMarkdown v2 使用error = FALSE.请参阅下面乔希评论中的链接.

Short explanation, RMarkdown v1 used error = TRUE by default, but RMarkdown v2 uses error = FALSE. See the link in Josh's comment below.

推荐答案

不要使用 rstudio 中的按钮进行编译.试试:

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

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

这篇关于无法解决 .Rmd 文件中的错误 &lt;Anonymous&gt;... withCallingHandlers ->withVisible ->评估 ->评估 ->的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆