+ - 0:00:00
Notes for current slide
Notes for next slide



R packages: Part II

Dr. Mine Dogucu

1 / 11

Data in R packages

  • For disseminating data
  • For examples in vignettes and other documentation
  • For tests (keep it simple)
2 / 11

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)

✓ 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
3 / 11

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

  • @export is not used for datasets.

  • Once you are done documenting, do not forget to devtools::document.

4 / 11

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

5 / 11

Writing vignettes

> 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'
>
>
6 / 11

pkgdown

pkgdown is a package that makes it easy to build a website for R packages.

# To configure your package to use pkgdown
usethis::use_pkgdown()
# build the website
pkgdown::build_site()

Example bayesrules

7 / 11

DESCRIPTION

Example

8 / 11

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.

9 / 11

Author information

  • cre creator or maintaner of the package.
  • aut authors
  • ctb contributors
  • cph copyright holder
10 / 11

Version number

  • major.minor.patch is a version number system for released packages.

  • e.g. We are using version 2.4.2 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.

11 / 11

Data in R packages

  • For disseminating data
  • For examples in vignettes and other documentation
  • For tests (keep it simple)
2 / 11
Paused

Help

Keyboard shortcuts

, , Pg Up, k Go to previous slide
, , Pg Dn, Space, j Go to next slide
Home Go to first slide
End Go to last slide
Number + Return Go to specific slide
b / m / f Toggle blackout / mirrored / fullscreen mode
c Clone slideshow
p Toggle presenter mode
t Restart the presentation timer
?, h Toggle this help
Esc Back to slideshow