Skip to contents

This document gives an outline of concepts relevant to the development of the community package. Each section presents questions or exercises to consider.

Data Background

Data Alignment

  1. What is the value of value in 2015?
##   value year
## 1     1 2012
## 2     2 2013
## 3     3 2014

Answer: NA; the year 2015 does not exist here, but we can still virtually access it.

  1. What is the mean absolute error between the values of d1 and d2?
## $d1
##   value year
## 1     1 2012
## 2     2 2013
## 3     3 2014
## 
## $d2
##   value year
## 1     1 2013
## 2     2 2014
## 3     3 2015

Answer: MAE = 1; to calculate this, we need to temporally align vectors (which could be done virtually):

##   year d1 d2
## 1 2012  1 NA
## 2 2013  2  1
## 3 2014  3  2
## 4 2015 NA  3

ID Mapping

  1. If ID 123 is selected, which rows should be included?
##     ID
## 1 1234
## 2 1243
## 3 1235
## 4 1245

Answer: rows 1 (1234) and 3 (1235); with no additional information, we can look for initial substring matches to map one set of IDs to another.

  1. Calculate all possible aggregates of the lower dataset values to the higher dataset.
## $higher
##    ID time v1 v2
## 1 123    1 NA NA
## 2 124    1 NA NA
## 3 123    2 NA NA
## 4 124    2 NA NA
## 
## $lower
##     ID time v1 v2
## 1 1234    1 10  1
## 2 1243    1  5 NA
## 3 1235    1 20  3
## 4 1245    1 13 NA
## 5 1234    2  7  5
## 6 1243    2 15 NA
## 7 1235    2 18 NA
## 8 1245    2 23 NA

Aggregated higher:

##    ID time   v1 v2
## 1 123    1 15.0  2
## 2 124    1  9.0 NA
## 3 123    2 12.5  5
## 4 124    2 19.0 NA

We only ever calculate mean aggregates – this is just a way to fill out numbers, as appropriate aggregates should always be included, rather than calculated here.

R Packaging Background

Documentation

Edit the description of the dir argument of the site_build function.

  1. Where would you make that change?

  2. How would you get that change to appear in the local R help (?site_build)?

  3. How would you get that change to appear on the documentation site (site_build.html)?

Debugging

This is an exercise about stepping into a running function:

Without editing any source code, calculate the row means of cols after it has been updated in

util_make_palette(rep(c("red", "green", "blue"), each = 10), polynomial = TRUE)

Expected result:

##   red green  blue 
##   102    51   102

Testing

Write a test to cover the first uncovered line of the datacommons_refresh function.

  1. How would you update the coverage report?

JavaScript Background

Build Tools

  1. The npm start command is a shortcut. What is the underlying command?

  2. What does npm run find-deadcode do, and when might you want to run it?

Editing Source

  • Add a line of code that will log to the console whenever a dataset is loaded.
    1. How would you see if it works?
    2. How would you push that change out to a live site?
  • There is functionality to display information about a variable when its name is clicked on. Change that display to show a piece of information that isn’t currently being shown.
    1. How would you see what information is available?

Testing

Take a look at the coverage of the data handler > checks > value_checks object, and note that some functions are not covered (such as !=).

Write a test to cover one of those functions.

  1. How would you update the coverage report?

  2. How would you trigger that function in a browser console?