Skip to content

Including data

Katie Paulson edited this page Aug 6, 2020 · 2 revisions

It can be really useful to include example data in packages. It allows users to immediately have a dataset that is formatted to work with the package functions. It can also be a good way to distribute topic specific data. For example the UN WPP results.

Steps:

  1. Use usethis::use_data_raw(name) to create a .R file in the data-raw directory.
  2. Add code to this file to generate a data file. At the end of this script, use usethis::use_data to save a .rda file to the data directory.
  3. Create a file R/data.R. Here, you can use Roxygen syntax to create documentation on the dataset.
  4. Then, data can be loaded into your workspace with data().

See Hadley's R packages book for more details.