Skip to content

How to add a dataset to this package

Angela Li edited this page Jul 20, 2020 · 9 revisions
  1. Clone the repository to your computer. Instructions for how to clone the repository into an R project can be found in Happy Git with R. Before doing this, ensure that you have connected RStudio to Git and Github.
  2. Store the original data from the GeoDa data site as a .shp file (or other raw spatial data format) in data-raw. Note that you need all four files, .shp/.dbf/.shx/.prj for a shapefile. You can also use a standalone .gpkg or .geojson if needed.
  3. Create a new cleaning script in data-raw called clean-XXX.R (XXX should be the name of the raw data file, for consistency). You can copy one of the existing scripts. Make sure to save an sf object in the data folder using the usethis::use_data() function in the script.
  4. Create a new documentation script in the R folder called the name of the dataset, ie nyc.R. Follow the same format as one of the existing scripts in R. Ensure that the dataset name is exactly the same name as the .rda file in data. You can look up information about the projection/EPSG code included with the dataset at this link. For more on documenting data, check out the R Packages book.
  5. Run devtools::document() in the console to write the .Rd files from the roxygen2 headers. These files are stored in the man folder and should not be edited.
  6. Run devtools::install() in the console (or click on "Install and Restart" in the Build panel) to build the package and restart R. Check that nyc and ?nyc both work. You added a new dataset to the package!
  7. Run pkgdown::build_site() in the console to build the package website from the new documentation.
  8. Add, commit and push your changes.
  9. (optional) You can edit README.Rmd to mention the dataset you just added. Click "Knit" and it will generate README.md (the reason for this workflow is in case you want to include runnable R code in the README).

For additional reading on how to develop an R package, you can read R Packages or the rOpenSci package development guide.

Clone this wiki locally