<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/introducing-learnr/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://blog.rstudio.com/2017/07/11/introducing-learnr/"> Home on RStudio Blog</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>We’re pleased to introduce the <a rel="nofollow" href="https://rstudio.github.io/learnr/" target="_blank">learnr</a> package, now available on CRAN. The learnr package makes it easy to turn any R Markdown document into an interactive tutorial. Tutorials consist of content along with interactive components for checking and reinforcing understanding. Tutorials can include any or all of the following:</p>
<ul>
<li>
<p>Narrative, figures, illustrations, and equations.</p>
</li>
<li>
<p>Code exercises (R code chunks that users can edit and execute directly).</p>
</li>
<li>
<p>Multiple choice quizzes.</p>
</li>
<li>
<p>Videos (supported services include YouTube and Vimeo).</p>
</li>
<li>
<p>Interactive Shiny components.</p>
</li>
</ul>
<p><a rel="nofollow" href="https://tutorials.shinyapps.io/04-Programming-Basics/" target="_blank"><img alt="learnr-blog-1" src="https://rstudioblog.files.wordpress.com/2017/06/learnr-blog-1.png?w=456" data-recalc-dims="1"></a></p>
<p>Each learnr tutorial is a Shiny interactive document, which means that tutorials can be deployed all of the same ways that Shiny applications can, including locally on an end-user’s machine, on a Shiny or RStudio Connect Server, or on a hosting service like <a rel="nofollow" href="http://shinyapps.io/" target="_blank">shinyapps.io</a>.</p>
<h3>Getting Started</h3>
<p>To create a learnr tutorial, install the learnr package with</p>
<pre><code>install.packages(&quot;learnr&quot;)
</code></pre>
<p>Then select the Interactive Tutorial template from the <strong>New R Markdown</strong> dialog in the RStudio IDE (v1.0.136 or later).</p>
<p><img alt="learnr-blog-2" src="https://rstudioblog.files.wordpress.com/2017/06/learnr-blog-2.png?w=456" data-recalc-dims="1"></p>
<h3>Exercises</h3>
<p>Exercises are interactive R code chunks that allow readers to directly execute R code and see it’s results:</p>
<p>To add an exercise, add <code>exercise = TRUE</code> to the chunk options of an R Markdown code chunk. R Markdown will preload the chunk with the code that you supply.</p>
<pre><code>```{r ex1, exercise = TRUE}
head(mtcars, n = 5)
```
</code></pre>
<p>becomes</p>
<p><img alt="learnr-blog-3" src="https://rstudioblog.files.wordpress.com/2017/06/learnr-blog-3.png?w=456" data-recalc-dims="1"></p>
<p>Exercises can include hints or solutions as well as custom checking code to provide feedback on user answers. The <a rel="nofollow" href="https://rstudio.github.io/learnr/exercises.html" target="_blank">learnr Exercises page</a> includes a more in depth discussion of exercises and their various available options and behaviors.</p>
<h3>Questions</h3>
<p>You can include one or more <a rel="nofollow" href="https://rstudio.github.io/learnr/questions.html" target="_blank">multiple-choice quiz questions</a> within a tutorial to help verify that readers understand the concepts presented. Questions can have a single or multiple correct answers.</p>
<p>Include a question by calling the <code>question()</code> function within an R code chunk:</p>
<pre><code>```{r letter-a, echo=FALSE}
question(&quot;What number is the letter A in the English alphabet?&quot;,
  answer(&quot;8&quot;),
  answer(&quot;14&quot;),
  answer(&quot;1&quot;, correct = TRUE),
  answer(&quot;23&quot;)
)
```
</code></pre>
<p><img alt="learnr-blog-4" src="https://rstudioblog.files.wordpress.com/2017/06/learnr-blog-4.png?w=456" data-recalc-dims="1"></p>
<h3>Videos</h3>
<p>You can include videos published on either YouTube or Vimeo within a tutorial using the standard markdown image syntax. Note that any valid YouTube or Vimeo URL will work. For example, the following are all valid examples of video embedding:</p>
<pre><code>![](https://youtu.be/zNzZ1PfUDNk)
![](https://www.youtube.com/watch?v=zNzZ1PfUDNk)

![](https://vimeo.com/142172484)
![](https://player.vimeo.com/video/142172484)
</code></pre>
<h3>Code checking</h3>
<p>learnr works with external code checking packages to let you evaluate student answers and provide targeted, automated feedback, like the message below.</p>
<p><img alt="learnr-blog-5" src="https://rstudioblog.files.wordpress.com/2017/06/learnr-blog-5.png?w=456" data-recalc-dims="1"></p>
<p>You can use any package that provides a learnr compatible <a rel="nofollow" href="https://rstudio.github.io/learnr/exercises.html#exercise_checking" target="_blank">checker function</a> to do code checking (the <a rel="nofollow" href="https://github.com/dtkaplan/checkr" target="_blank">checkr</a> package provides a working prototype of a compatible code checker).</p>
<h3>Navigation and progress tracking</h3>
<p>Each learnr tutorial includes a Table of Contents that tracks student progress. learnr remembers which sections of a tutorial a student completes, and returns a student to where they left off when they reopen a tutorial.</p>
<p><img alt="learnr-blog-6" src="https://rstudioblog.files.wordpress.com/2017/06/learnr-blog-6.png?w=456" data-recalc-dims="1"></p>
<h3>Progressive Reveal</h3>
<p>learnr optionally reveals content one sub-section at a time. You can use this feature to let students set their own pace, or to hide information that would spoil an exercise or question that appears just before it.</p>
<p>To use progressive reveal, set the <code>progressive</code> field to true in the yaml header.</p>
<pre><code>---
title: &quot;Programming basics&quot;
output:
  learnr::tutorial:
    progressive: true
    allow_skip: true
runtime: shiny_prerendered
---
</code></pre>
<p>Visit <a rel="nofollow" href="https://rstudio.github.io/learnr/" target="_blank">rstudio.github.io/learnr/</a> to learn more about creating interactive tutorials with learnr.</p>
	<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://blog.rstudio.com/2017/07/11/introducing-learnr/"> Home on RStudio Blog</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a rel="nofollow" href="https://www.r-project.org/" title="The R Project for Statistical Computing">R</a> news and <a rel="nofollow" href="https://www.r-bloggers.com/search/tutorial" title="R tutorials">tutorials</a> on topics such as: <a rel="nofollow" href="https://www.r-bloggers.com/search/data%20science" title="Data science">Data science</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data" title="Big Data">Big Data, <a rel="nofollow" href="https://www.r-users.com/" title="R jobs">R jobs</a>, visualization (<a rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2" title="ggplot and ggplot2 tutorials">ggplot2</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/boxplot" title="Boxplots using lattice and ggplot2 tutorials">Boxplots</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/map" title="Maps and gis">maps</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/animation" title="Animation in R">animation</a>), programming (<a rel="nofollow" href="https://www.r-bloggers.com/search/RStudio" title="RStudio IDE for R">RStudio</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/sweave" title="Sweave and literate programming">Sweave</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX" title="LaTeX in R">LaTeX</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/SQL" title="SQL and databases">SQL</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/eclipse" title="Eclipse IDE for R">Eclipse</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/git" title="git and github, Version Control System">git</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/hadoop" title="Large data in R using Hadoop">hadoop</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping" title="Web Scraping of google, facebook, yahoo, twitter and more using R">Web Scraping</a>) statistics (<a rel="nofollow" href="https://www.r-bloggers.com/search/regression" title="Regressions and ANOVA analysis tutorials">regression</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/PCA" title="principal component analysis tutorial">PCA</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/time+series" title="Time series">time series</a>, <a rel="nofollow" href="https://www.r-bloggers.com/search/trading" title="finance trading">trading</a>) and more...
<img width="1" alt="" src="http://feeds.feedburner.com/~r/RBloggers/~4/DO9NJ-xlr9U" height="1"></a></div>