gpt4 book ai didi

r - 无法解决 .Rmd 文件 中的错误... withCallingHandlers -> withVisible -> eval -> eval ->

转载 作者:行者123 更新时间:2023-12-02 02:40:16 24 4
gpt4 key购买 nike

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

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)
```

当我尝试将其编织为任何格式时,我收到错误

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 文件中路径设置不正确的问题。

由于我在这里只使用基本函数,并且没有引用任何文件(无论如何,我都知道),所以我不认为这些都是我的问题(但我很乐意犯错) )。

关于我需要做什么才能编织文档有什么建议吗?

解决方案

将以下内容添加到 .Rmd 顶部

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

简单说明一下,RMarkdown v1 默认使用 error = TRUE,但 RMarkdown v2 使用 error = FALSE。请参阅下面 Josh 评论中的链接。

最佳答案

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

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

关于r - 无法解决 .Rmd 文件 <Anonymous> 中的错误... withCallingHandlers -> withVisible -> eval -> eval ->,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30519673/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com