Due Friday November 27.

Big picture

Templates you can follow

Please just tell me what to do

If you don’t feel like dreaming up your own thing, here’s a Gapminder blueprint that is a minimal but respectable way to complete the assignment. You are welcome to remix R code already written by someone, student or JB, in this class, but credit/link appropriately, e.g. in comments.

JB has provided a template, using a different dataset, 01_justR, that should help make this concrete.

Download the data

Download the raw data for our example, gapminder.tsv.

  • Option 1: via an R script using downloader::download or RCurl::getURL. note: download.file does not work with https://

    downloader::download("https://raw.githubusercontent.com/jennybc/gapminder/master/inst/gapminder.tsv")
    cat(file = "gapminder.tsv",
      RCurl::getURL("https://raw.githubusercontent.com/jennybc/gapminder/master/inst/gapminder.tsv"))
  • Option 2: in a shell script using curl or wget.

    curl -O https://raw.githubusercontent.com/jennybc/gapminder/master/inst/gapminder.tsv
    wget https://raw.githubusercontent.com/jennybc/gapminder/master/inst/gapminder.tsv

Perform exploratory analyses

  • Bring the data in as data frame.
  • Save a couple descriptive plots to file with highly informative names.
  • Reorder the continents based on life expectancy. You decide the details.
  • Sort the actual data in a deliberate fashion. You decide the details, but this should at least implement your new continent ordering.
  • Write the Gapminder data to file(s), for immediate and future reuse.

Perform statistical analyses

  • Import the data created in the first script.
  • Make sure your new continent order is still in force. You decide the details.
  • Fit a linear regression of life expectancy on year within each country. Write the estimated intercepts, slopes, and residual error variance (or sd) to file.
  • Find the 3 or 4 “worst” and “best” countries for each continent. You decide the details.
  • Write the linear regression info for just these countries to file.

Generate figures

Create a figure for each continent, including data only for the 6-8 “extreme” countries, and write to file. One file per continent, with an informative name. The figure should give scatterplots of life expectancy vs. year, facetting on country, fitted line overlaid.

Automate the pipeline

Identify and test a method of running your pipeline non-interactively.

You could write a master R script that simply source()s the three scripts, one after the other. Tip: you will probably want a second “clean up / reset” script that deletes all the output your scripts leave behind, so you can easily test and refine your strategy, i.e. without repeatedly deleting stuff “by hand”. You can run the master script or the cleaning script from a shell with R CMD BATCH or Rscript.

Provide a link to a page that explains how your pipeline works and links to the remaining files. Your peers and the TAs should be able to go to this landing page and re-run your analysis quickly and easily. Consider including an image showing a graphical view of your pipeline.

I want to aim higher!

Follow the basic Gapminder blueprint above, but find a different data aggregation task, different panelling/faceting emphasis, focus on different variables, etc.

Use non-Gapminder data – like maybe the candy survey?

This means you’ll need to spend more time on data cleaning and sanity checking. You will probably have an entire script (or more!) devoted to data prep. Examples:

Include some dynamic report generation in your pipeline. That is, create HTML from one or more plain R or R markdown files.

Experiment with running R code saved in a script from within R Markdown. Here’s some official documentation on code externalization.

Embed pre-existing figures in and R Markdown document, i.e. an R script creates the figures, then the report incorporates them. General advice on writing figures to file is here. See an example of this in an R Markdown file in one of the examples.

Import pre-existing data in an R Markdown document, then format nicely as a table.

Use Pandoc and/or LaTeX to explore new territory in document compilation. You could use Pandoc as an alternative to rmarkdown (or knitr) for Markdown to HTML conversion; you’d still use rmarkdown for conversion of R Markdown to Markdown. You would use LaTeX to get PDF output from Markdown.

Use Make to run your pipeline. See below for help. Also demonstrated in the example 02_rAndMake and in the example 03_knitWithoutRStudio

Authors

Written by Shaun Jackman and Jenny Bryan.