class: title-slide <br> <br> .right-panel[ # R packages: Part II ## Dr. Mine Dogucu ] --- class: middle ## Data in R packages - For disseminating data - For examples in vignettes and other documentation - For tests (keep it simple) --- class: middle ## Data in R packages - If any of your data needs wrangling, make sure to record this in an `.R` file stored in `data-raw` folder. - Once you are done wrangling the data, you can write the data by `usethis::use_data(data_frame_name, overwrite = TRUE)` ```r ✓ Setting active project to '/Users/minedogucu/Desktop/mypackage' ✓ Adding 'R' to Depends field in DESCRIPTION ✓ Creating 'data/' ✓ Saving 'mtcars_sample' to 'data/mtcars_sample.rda' • Document your data (see 'https://r-pkgs.org/data.html') ``` - Make sure to add `^data-raw$` to `.Rbuildignore` --- class: middle ## Documenting Data - In `R/data_mtcars_sample.R` document the data. - The `data` prefix in the file name helps distinguish functions and packages. - Example from [bayesrules](https://github.com/bayes-rules/bayesrules/blob/master/R/data_big_word_club.R) - `@export` is not used for datasets. - Once you are done documenting, do not forget to `devtools::document`. --- class: middle ## Writing vignettes - Vignettes are longer form of documentation. - It is especially useful if you are introducing a set of packages that are related to each other. - Example: [stringr's regular expressions vignette](https://cran.r-project.org/web/packages/stringr/vignettes/regular-expressions.html) --- class: middle ## Writing vignettes ```r > usethis::use_vignette("my-vignette") ✓ Adding 'knitr' to Suggests field in DESCRIPTION ✓ Setting VignetteBuilder field in DESCRIPTION to 'knitr' ✓ Adding 'inst/doc' to '.gitignore' ✓ Creating 'vignettes/' ✓ Adding '*.html', '*.R' to 'vignettes/.gitignore' ✓ Adding 'rmarkdown' to Suggests field in DESCRIPTION ✓ Writing 'vignettes/my-vignette.Rmd' • Modify 'vignettes/my-vignette.Rmd' > > ``` --- class: middle ## pkgdown `pkgdown` is a package that makes it easy to build a website for R packages. ```r # To configure your package to use pkgdown usethis::use_pkgdown() ``` ```r # build the website pkgdown::build_site() ``` Example [bayesrules](https://bayes-rules.github.io/bayesrules/docs/) --- class: middle ## DESCRIPTION [Example](https://github.com/bayes-rules/bayesrules/blob/master/DESCRIPTION) --- class: middle ## Imports vs. Suggests **Imports:** Any time your package is installed these packages will be installed. They are required for your package to work. **Suggests** These may be required for running tests, building vignettes, etc. --- class: middle ## Author information - `cre` creator or maintaner of the package. - `aut` authors - `ctb` contributors - `cph` copyright holder --- class: middle ## Version number - `major.minor.patch` is a version number system for released packages. - e.g. We are using [version 2.4.2](https://cran.r-project.org/web/packages/devtools/index.html) of devtools which indicates 2 is the major number, 4 is the minor number, and the last 2 is the patch number. - Developers continue to work on their packages even after release and this usually is indicated with .9000 at the end of the version number. For instance devtools version on GitHub is currently [2.4.2.9000](https://github.com/r-lib/devtools/blob/main/DESCRIPTION).