rmarkDown Backticks内联代码 /与通常的代码块不一致的行为不一致

发布于 2025-01-29 18:01:44 字数 496 浏览 2 评论 0原文

这在R Markdown中的通常代码块中起作用:

m1_aov <- anova(m1)
m1_aov$`Sum Sq`[2] %>% round(3)

不幸的是,使用内联代码中的后者破坏了knitr解析器

`r m1_aov$`Sum Sq`[2] %>% round(3)`

确实会破坏stackoverflow。

我看着这个相关问题,但无法推断出我的问题的工作解决方案。有暗示吗?

This works in a usual code chunk in R markdown:

m1_aov <- anova(m1)
m1_aov

This works in a usual code chunk in R markdown:

Sum Sq`[2] %>% round(3)

Unfortunately, using the latter in inline code breaks the knitr parser down

`r m1_aov

This works in a usual code chunk in R markdown:

m1_aov <- anova(m1)
m1_aov

This works in a usual code chunk in R markdown:

Sum Sq`[2] %>% round(3)

Unfortunately, using the latter in inline code breaks the knitr parser down

Sum Sq`[2] %>% round(3)`

Indeed, it also breaks Stackoverflow.

I looked at this related question but could not infer a working solution to my problem. Any hint?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云之铃。 2025-02-05 18:01:44

用一个工作的示例扩展评论:

---
output: html_document
---

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

## R Markdown

```{r}
a <- tibble::tibble(`a column` = 1:10) # using tibble to get a column name with a white space
m <- mean(a

用一个工作的示例扩展评论:

a column`) ``` Mean is `r m`

对我来说,这看起来像是一个整洁的技巧,因为它避免在文本中包含不必要的长代码,并且不要以创建新对象的(小)成本来创建您面临的问题。

输出:

Expanding the comment with a working example:

---
output: html_document
---

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

## R Markdown

```{r}
a <- tibble::tibble(`a column` = 1:10) # using tibble to get a column name with a white space
m <- mean(a

Expanding the comment with a working example:

a column`) ``` Mean is `r m`

To me this looks like a neat trick because it avoids to include unecessary long code inside the text, and do not create the problem you are facing at the (small) cost of creating new objects.

The output:
enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文