Skip to content

Instantly share code, notes, and snippets.

@matt-dray
Last active June 5, 2024 16:03
Show Gist options
  • Save matt-dray/e3877159c6a8f8a65ca35b5229035524 to your computer and use it in GitHub Desktop.
Save matt-dray/e3877159c6a8f8a65ca35b5229035524 to your computer and use it in GitHub Desktop.
Steps to create an exported dataset in an R package with {usethis}
  1. In your package project, run usethis::use_data_raw("demo-data") to set up a data-raw/ folder with a demo-data.R file inside.
  2. Write a script in demo-data.R to produce the data object (e.g. demo_df).
  3. Insert and run the line usethis::use_data(demo_df) in demo-data.R, which will save the data object to a data/demo_df.rda file.
  4. Run usethis::use_r("demo-data") to create a corresponding R/demo-data.R file where you can document the data.
  5. In R/demo-data.R, quote the name of the data object (i.e. "demo_df") and put {roxygen2} code above it (probably at least @title, @description and maybe @format, which might contain a \describe{} block to explain the content of your object, itself containing an \item{} to describe each column if it's a data.frame).
  6. Run devtools::document() to generate the man/ pages for the data.
  7. Run devtools::load_all() to reload your package and make demo_df available in your session.
  8. Once pushed, users can attach the package and access demo_df by name, or access it with package::demo_df namespacing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment