Search code examples
rr-packagelearnr

How can I wrap an interactive R learnr tutorial in a package?


I’m new to creating learnr tutorials and even more to creating packages, but after reading tutorials on these two topics, I can now create simple packages and simple learnr tutorials. Now that I know a bit about both topics, I would like to deploy my interactive tutorials in a basic package, but there are not many resources available. Can you show me how to do this in the simplest possible way?


Solution

  • You'll need to:

    1. Create a package
    2. Use a tutorial inside that package

    1. Create a package

    Check the chapter 2 of R Packages by Hadley Wickham. You'll understand how to start one by using:

    library(devtools)
    
    create_package("path/to/package")
    

    2. Use a tutorial inside that package

    Once you started a package you'll need to create a tutorial inside the inst directory of your package. use_tutorial() does it for you. Be sure to be in the package project inside RStudio.

    usethis::use_tutorial(name, title)
    

    That's all. Be sure to check the learnr documentation for more details. More steps in https://education.rstudio.com/blog/2020/09/delivering-learnr-tutorials-in-a-package/