I'm writing a teaching document, in which I would like to hide some function and variable names, so the students have to rewrite themselves, but I still want to display the correct result. For example, this would be one code chunk:
# print 1+1
x <- 1 + ___
___(x)
#> 2
One solution that works is to write two code chunks:
That way, the students see the content of first code chunk, and the results of the second one. This works, but is a bit unpractical with tens of code chunks.
I feel this should be a common thing to do, and there are probably better solutions available, but couldn't really find anything with the keywords I tried.
The easiest option is probably to take advantage of built-in features for collapsing code chunk. See the rmarkdown manual for help.
Another option is the functionality for a software carpentry lesson (see the 'episodes' directory for examples) but that is more complicated to implement.
My understanding (and experience) with collapsing is that the student then gets control and can choose to display nothing or everything. If I'm not mistaken, that is also what software carpentry uses (in their "Challenges").
Here I would like to keep control of what is displayed, and censor a few words, without giving the students the possibility to show them.
Your description of these resources is accurate. What you are asking for sounds like a lot of complicated programming that is not currently enabled in rmarkdown, but I could be wrong.