我想知道是否可以运行代码块的一部分而不注释我们不想运行的行。例如我们有以下 qmd 文件:
---
title: "Run only part of code chunk without commenting"
---
```{r}
data(trees)
head(trees)
plot(Girth ~ Height, data = trees, pch=16)
mod <- lm(Girth ~ Height, data = trees)
summary(mod)
```
Run Code Online (Sandbox Code Playgroud)
假设我们只想运行第 6 行到第 9 行,我们该怎么做呢?我不想使用这样的评论:
---
title: "Run only part of code chunk without commenting"
---
```{r}
data(trees)
head(trees)
plot(Girth ~ Height, data = trees, pch=16)
#mod <- lm(Girth ~ Height, data = trees)
#summary(mod)
```
Run Code Online (Sandbox Code Playgroud)
这样做的主要原因是我想显示完整的代码但不想运行所有代码。当我们对某些行进行评论时,看起来不太好。所以我想知道是否有人知道这是否可能Quarto?
您可以使用它eval = 1:4来选择将运行的代码行,但它会自动将它们注释掉。您还可以使用#| eval: !expr 1:4它使其更加四开本。
---
title: "Run only part of code chunk without commenting"
---
```{r, eval = 1:4}
data(trees)
head(trees)
plot(Girth ~ Height, data = trees, pch=16)
mod <- lm(Girth ~ Height, data = trees)
summary(mod)
```
Run Code Online (Sandbox Code Playgroud)