小编tha*_*sic的帖子

有没有办法在Rmarkdown中执行条件降价块执行?

我是一名教师,希望通过更改我创建的文档参数,从同一个Rmarkdown文件中完成作业和家庭作业解决方案指南soln.当soln=FALSE生成分配文件,并且当soln=TRUE生成了作业溶液指南.我可以使用document参数控制R代码块执行,但我还希望条件包含markdown文本.

我目前的解决方法很难看:

---
title: "Homework"
output: word_document
params:
  soln: TRUE
---
Fit the linear regression model $Y \sim X$ with the following data.     
Interpret the coefficient estimates.
```{r promptchunk, include = TRUE, echo = TRUE}
# R code I want to show in the question prompt goes here
# This executes in both assignment and solution versions
set.seed(123)
X <- c(1, 1, 0, 0)
Y <- rnorm(4)
```
```{r, include = params$soln, echo = …
Run Code Online (Sandbox Code Playgroud)

markdown r pandoc knitr r-markdown

18
推荐指数
2
解决办法
4815
查看次数

标签 统计

knitr ×1

markdown ×1

pandoc ×1

r ×1

r-markdown ×1