RMarkdown workflow

  1. In your project, create two directories: scripts and reports

  2. Create a script prepare.R in the scripts directory

  3. Create an RMarkdown document from template, save it as final.Rmd in the reports directory.

  4. Add code to prepare.R to transform the flights data in some way. (Use subsetting, add new variables, or compute a summary. Anything works.) Assign the result to a global variable using <-. Save this variable to a file using the saveRDS() function.

    Hint: Use library(here) and here() to control where the file is saved.

  5. Leave only the header and the “setup” chunk in final.Rmd. In the “setup” chunk, insert a call to the readRDS() function for the file you saved in the previous step.

    Hint: Use here again, you should be using the same file name that you have used for saveRDS().

  6. Knit the document. This should work without failure (but show an empty document).

  7. Create a second code chunk that shows a plot of your transformed data. Do not refer to flights. Knit again.

Slides and reports

  1. Choose File / New File / R Markdown… from the RStudio menu. In the dialog, select “From template” in the pane on the left-hand side and then “Ninja presentation” to create an example slide deck. Knit it.

  2. What templates are available from the “rticles” package? Are any of them useful for your work?

  3. Navigate to https://github.com/rstudio/bookdown-demo (or search for “bookdown demo” in a search engine). Extract the demo to a directory of your choice, and follow the instructions in the README.md file.

Copyright © 2019 Kirill Müller. Licensed under CC BY-NC 4.0.