knitr
utility to convert your static code chunks into an R editor where people can experiment. Powered by DataCamp Light, a lightweight version of DataCamp’s learning interface.
Add the following chunk at the top of your R Markdown document
Knit your document: in RStudio, simply hit “Knit HTML”, or use
R vignettes, blog posts and teaching material are typically standard web pages generated with R markdown. DataCamp has developed a framework to make this static content interactive: R code chunks are converted into an R-session backed editor so readers can experiment.
If you render an R Markdown document like this:
---
title: "Example Document"
author: "Your name here"
output:
html_document:
self_contained: false
---
```{r, include=FALSE}
tutorial::go_interactive()
```
By default, `tutorial` will convert all R chunks.
```{r}
a <- 2
b <- 3
a + b
```
An HTML file results that features an in-browser R editor with a session attached to it, where you can experiment.
Notice that the option self_contained: false
is used. That way, always the latest version of the DataCamp Light JS library is fetched when the document is opened. If self_contained: true
, the version of the JS library at ‘knit time’ is baked into the HTML document. This can cause backwards compatibility issues.
You can also embed coding challenges into your webpages. This group of code chunks:
```{r ex="create_a", type="pre-exercise-code"}
b <- 5
```
```{r ex="create_a", type="sample-code"}
# Create a variable a, equal to 5
# Print out a
```
```{r ex="create_a", type="solution"}
# Create a variable a, equal to 5
a <- 5
# Print out a
a
```
```{r ex="create_a", type="sct"}
test_object("a")
test_output_contains("a", incorrect_msg = "Make sure to print `a`.")
success_msg("Great!")
```
Converts to the following DataCamp Light exercise:
You can power your package’s vignettes with DataCamp Light by adding the same line to the top of your vignette:
---
title: "Tutorial Basics"
author: "Filip Schouwenaars"
date: "`r Sys.Date()`"
output: rmarkdown::html_vignette
vignette: >
%\VignetteIndexEntry{Tutorial Basics}
%\VignetteEngine{knitr::rmarkdown}
%\VignetteEncoding{UTF-8}
---
```{r, include=FALSE}
tutorial::go_interactive()
```
_remainder of vignette omitted_
For more details, questions and suggestions, you can contact content-engineering@datacamp.com.