Objective

This package is a proof-of-concept to utilize knitr code block to hide part of the content in the generated html document. For each hidden block, a question will be promoted to the user – once it is correctly answered, the actual content will be shown.

Though this package is just a toy, this approach may be useful to create interactive tutorial in rmarkdown, or to create a semi-public blog post with blogdown package.

Installation

Use the following code to install the package.

devtools::install_github("Marlin-Na/asku")

Example

To use the knit engine, you should first load the package in your rmarkdown document before using the “asku” knit engine.

library('asku')
```{asku, Q="What do you get if you multiple 6 by 9?", A="42"}
**Yes, you get the right answer!**

By default, you can use `markdown` syntax here, which makes it easier
to format your hidden content.

This is the first time that I try to create a custom knitr engine.
I feel that its name is quite appropiate to describe the nature of
`knitr`. Things are interconnected in `knitr` -- code chunks, results
and metadata -- instead of simply evaluating the code and put them back.

![](https://raw.githubusercontent.com/yihui/yihui.name/master/content/knitr/images/knit-logo.png)

Like the universe:
    
> The connections between causes and effects are often much more subtle
> and complex than we with our rough and ready understanding of the physical
> world might naturally suppose.... You wouldn't believe it. Things, double up.
> They parallel. Everything is chaos, but it's synchronized.
> There's always something ready to mirror itself, life endlessly turning inward.

----------
```

The code chunk above in your rmarkdown file will generate the following in html document. Try to enter the answer (it is specified as option of the code chunk)! If it is correct, the content in the code block will be displayed.


What do you get if you multiple 6 by 9?

How does it work

The asku function utilizes htmltools to generate html fragments that can be included in html documents. Then a custom knitr engine is implemented to enable writing the hidden content directly in Rmarkdown.

Warning

Currently, the hidden content is NOT encrypted. Ideally, a encryption method should be implemented with answer as the key. So that the content is encrypted on R side and decrypted in browser using the key.