Packages

Moritz Friedrich, Klemens Kurtz
2018-05-14

Packages?

  • 2018-04-30 the CRAN package repository features 12.556 available packages.
  • Probably the reason why R is so successfull.
  • Somebody might have solved your problem.
  • https://cran.r-project.org/

Source: revolutionanalytics.com (2017)

Packages?

A bundle of functions, data sets and help pages that you install in addition to the base R installation.

Source: R-Studio

Why would we need our own package?

  • The main purpose is not to put your package on CRAN.
  • Organise your code to make your life easier - there are conventions!
  • They save you time - you don’t need to think about the best way to organise a project, you can just follow a template.
  • Standardised conventions lead to standardised tools - if you buy into R’s package conventions, you get many tools for free.
  • Also share code in a convinient way - (b2b, via github, …)
Seriously, it doesnt have to be about sharing your code (although that is an added benefit!). It is about saving yourself time.” Parker (2014)

Source: Wickham (2015)

Vignettes

Source: Wickham (2015)

Tests

  • make sure you code still works after changes
  • initialize with devtools::use_testthat()
  • put your tests (R-files starting with “test” in the name) in tests/testthat/
  • run them all with devtools::test()

Source: Wickham (2015)

Resources