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

Zen and the Art of R Package development

Malcolm Barrett

@malco_barrett

Slides: bit.ly/zenrpkgs

1

rstudio::conf(2020L)

2

rstudio::conf(2020L)

My Organizaton's First R Package

3

rstudio::conf(2020L)

My Organizaton's First R Package

R Markdown Driven Development

4
If you do not see the Way,
you do not see it
even as you walk on it

— Sandokai

5
If you do not see the R Package,
you do not see it
even as you develop it
6

You already
structure your project

7
├── data/
├── reports/
├── scripts/
└── analysis.Rproj
8
├── data/
├── reports/
├── R/
└── analysis.Rproj
9
├── data/
├── reports/
├── R/
└── analysis.Rproj
10
├── data/
├── vignettes/
├── R/
└── analysis.Rproj
11
├── data/
├── vignettes/
├── R/
├── man/
├── tests/
├── DESCRIPTION
├── NAMESPACE
└── analysis.Rproj
12

13
├── data/
├── vignettes/
├── R/
├── man/
├── tests/
├── DESCRIPTION
├── NAMESPACE
└── analysis.Rproj
14
Package: zenartofrpkgs
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R:
person(given = "Malcolm",
family = "Barrett",
role = c("aut", "cre"),
email = "malcolmbarrett@gmail.com",
comment = c(ORCID = "0000-0003-0299-5825"))
Description: What the package does (one paragraph).
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
15

16

You already
write R code

17

18

19

20

21

You already
declare your dependencies

22

23

24

25
Package: zenartofrpkgs
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R:
person(given = "Malcolm",
family = "Barrett",
role = c("aut", "cre"),
email = "malcolmbarrett@gmail.com",
comment = c(ORCID = "0000-0003-0299-5825"))
Description: What the package does (one paragraph).
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
26
Package: zenartofrpkgs
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R:
person(given = "Malcolm",
family = "Barrett",
role = c("aut", "cre"),
email = "malcolmbarrett@gmail.com",
comment = c(ORCID = "0000-0003-0299-5825"))
Description: What the package does (one paragraph).
License: MIT + file LICENSE
Encoding: UTF-8
LazyData: true
Imports:
ggplot2
dplyr
27

28

You already
test your code

29

30

31

let's take a breath

32

Use a description file

33

Use a description file

Write code as functions

34

Use a description file

Write code as functions

Write down your tests; automate them

35
Each of you is perfect the way you are...
and you can use a
little improvement.

— Shunryu Suzuki Roshi

36
Each package is perfect the way it is...
and it can use a
little improvement

— Hadley Wickham

37

You already
document your code

38

39

40
#' Plot mean sepal length by species
#'
#' @param size the size of the points
#'
#' @return a ggplot
#' @export
#'
#' @examples
#'
#' plot_iris()
#'
plot_iris <- function(size = 2) {
iris %>%
dplyr::group_by(Species) %>%
dplyr::summarize(mean_sepal_length = mean(Sepal.Length)) %>%
ggplot2::ggplot(ggplot2::aes(mean_sepal_length, Species)) +
ggplot2::geom_point(size = 2)
}
41

42

You already
clean your data

43

44

45

You already
write reports

46

47

48

49

You already
share your code

50

51

Coming home
to R packages

52

an invitation

57

an invitation

create a package: a personal R package, something for your work, or turn a project into a package

58
The bad news is you’re falling
through the air, nothing to hang on to, no parachute.
The good news is there’s no ground.

— Chögyam Trungpa Rinpoche

59

What
next?

60

62

rstudio::conf(2020L)

2
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