6 learnr activities

6.1 Setting up

We’re going to embed some learnr activities now. The first one is “live” on the shinyapps.io server. It will walk you through setting up and running the other later tasks.

To do this, You’re going to download RStudio (if you haven’t already). Follow the tutorial below to do that.

#knitr::include_url("https://learnr-examples.shinyapps.io/ex-setup-r/")
knitr::include_app("https://learnr-examples.shinyapps.io/ex-setup-r/", height = "600px")

6.2 Downloading the resources

6.2.1 Getting the files

Ok, now we’re going to download these files from github, and run something.

  1. The code for this book is available at https://github.com/sjgknight/dsi/ You can download a set of interactive tutorials from https://github.com/sjgknight/learnr most of these were built by the great RStudio team and collaborators.

  2. There are three ways you can get the code:

    1. The easiest: Go to that repository, on the right hand side you’ll see “code” - click that, and “download zip” (or, direct link)Screenshot of github page, on the right there is a green code box, clicking that opens a menu to download a zip of the project code.

    2. Medium level: You can do the same thing using R. Now you’ve got R installed, you can run the code below to do this.

    3. Git-method: If you’re using git anyway (or, going to learn in Stats, Data Science Practice, or another subject) you might like to link the project to the repo, there are instructions for that at Happy Git and GitHub for the useR.

download.file(url = "https://github.com/sjgknight/learnr/archive/refs/heads/master.zip", destfile = "dsi-learnr.zip")  #if you want the book too, you can uncomment this line

# unzip the .zip file
unzip(zipfile = "dsi-learnr.zip")

6.2.2 Creating and opening projects

RStudio helps you manage projects. Make sure the download is unzipped in a location you want it on your machine:

  1. If you’ve downloaded an existing project, you might find the .Rproj file, and click that shows an image of the .Rproj logo
  2. Now you’re inside a project. Projects help you organise your work. They are associated with directories and their subdirectories. You can create new ones under the ‘File’ menu.
  3. Now you’ve opened the project, go to the instructions Rmd, open it, and follow along from there Shows file pane in RStudio with ‘instructions.Rmd’ highlighted
Allaire, JJ, Yihui Xie, Jonathan McPherson, Javier Luraschi, Kevin Ushey, Aron Atkins, Hadley Wickham, Joe Cheng, Winston Chang, and Richard Iannone. 2021. Rmarkdown: Dynamic Documents for r. https://CRAN.R-project.org/package=rmarkdown.
R Core Team. 2021. R: A Language and Environment for Statistical Computing. Vienna, Austria: R Foundation for Statistical Computing. https://www.R-project.org/.
Xie, Yihui. 2014. “Knitr: A Comprehensive Tool for Reproducible Research in R.” In Implementing Reproducible Computational Research, edited by Victoria Stodden, Friedrich Leisch, and Roger D. Peng. Chapman; Hall/CRC. http://www.crcpress.com/product/isbn/9781466561595.
———. 2015b. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. http://yihui.name/knitr/.
———. 2015a. Dynamic Documents with R and Knitr. 2nd ed. Boca Raton, Florida: Chapman; Hall/CRC. https://yihui.org/knitr/.
———. 2016. Bookdown: Authoring Books and Technical Documents with R Markdown. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/bookdown.
———. 2021a. Bookdown: Authoring Books and Technical Documents with r Markdown. https://CRAN.R-project.org/package=bookdown.
———. 2021b. Knitr: A General-Purpose Package for Dynamic Report Generation in r. https://yihui.org/knitr/.
Xie, Yihui, J. J. Allaire, and Garrett Grolemund. 2018. R Markdown: The Definitive Guide. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown.
Xie, Yihui, Christophe Dervieux, and Emily Riederer. 2020. R Markdown Cookbook. Boca Raton, Florida: Chapman; Hall/CRC. https://bookdown.org/yihui/rmarkdown-cookbook.