Packaging goods

introduction to package development

Anton Antonov (@tonytonov)

Motivation

Pros

  • portability, distribution
  • reproducibility, impact
  • huge time saver
  • quality control
  • do yourself a favor

Cons

  • cognitive effort
  • maintenance
  • there is no way back

Real life example

source("\\\\XXX.YYY.144.62\\[...]\\
       [...]_helper_functions_v2 - NEW.r")
library(yourpkg)

References

References

References

CRAN explosion

Overview

  1. Meta information
      DESCRIPTION
      NAMESPACE

  2. R code
      R/
  3. Documentation
      man/
  4. Tests
      tests/

DESCRIPTION

Front page of your package

  • Package name
  • Title
  • Authors/maintainers
  • Description
  • License
  • Imports (Depends, Suggests)

R code

R package is a tool,

so create functions, not objects

Be consistent

Documentation

Easily created via roxygen

  • Roxygen marker: #' 
  • @param name description
  • @return description
  • @importFrom package function
  • @export

NAMESPACE

  1. What is imported from other packages
  2. What is exported from your package
    (not every function should be exported)

roxygen will take care of it!

Tests

  1. Define expected behavior
  2. Run tests after each change

testthat will take care of it!

devtools

devtools::session_info
devtools::check
devtools::document
devtools::test
devtools::build

Package or library?

ggplot2
C:/Users/.../R/win-library/3.4
library(ggplot2)

"Go to library and load package ggplot2"

Package development

By Antonov Anton

Package development

The talk I gave at SPbR#10, R user group meetup (meetup.com/St-Petersburg-R-User-Group)

  • 566