我是一名教师,希望通过更改我创建的文档参数,从同一个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)