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

R Package Development

Jay Lee

2019/03/18

1 / 49

Motivation

library(ggplot2)
ggplot(data = mtcars) +
geom_bar(aes(x = factor(cyl), fill = factor(gear)))

2 / 49

Code/Function Reuse

  • Copy and paste from existinig code snippets

  • source("path/to/commonly/used/functions.R")

  • .Rprofile

  • library(my_awesome_pkg)

3 / 49

Cheet Sheet

  • Create an R package Project from RStudio

  • Change project options to use roxygen2

  • Delete R/hello.R, man/hello.Rd, and (default) NAMESPACE

  • Iterate through: write/load/document/check/install

  • Build source and share

4 / 49

R Package Development Screenshots

5 / 49

Create a new R project

project

6 / 49

New Directory

directory

7 / 49

New R Package

pkg

8 / 49

Naming is hard but fun!

pkg

9 / 49

Naming is hard but fun!

pkg

10 / 49

Hello World!

pkg

11 / 49

Bye World!

pkg

12 / 49

Bye World!

pkg

13 / 49

Bye World!

pkg

14 / 49

Bye World!

pkg

15 / 49

Bye (Default) NAMESPACE!

pkg

16 / 49

Bye (Default) NAMESPACE!

pkg

17 / 49

Change Project Options

pkg

18 / 49

Check Roxygen

pkg

19 / 49

Roxygen Option Not Available?

  • install.packages("roxygen2")

  • Save and restart RStudio Project (optional)

  • Return to Project Option

20 / 49

Check Roxygen

pkg

21 / 49

Check Roxygen

pkg

22 / 49

Write R Functions

pkg

23 / 49

Write R Functions

pkg

24 / 49

Load All Functions (cmd-shift-L)

pkg

25 / 49

Load All Functions (cmd-shift-L)

pkg

26 / 49

Load All Not Available?

  • install.packages("devtools")

  • Save and restart RStudio Project

  • Return to Build menu

27 / 49

Document

pkg

28 / 49

Document

pkg

29 / 49

Generate Documents (cmd-shift-D)

pkg

30 / 49

Generate Documents (cmd-shift-D)

pkg

31 / 49

Check (cmd-shift-E)

pkg

32 / 49

Check Progress

pkg

33 / 49

Check Warnings

pkg

34 / 49

Check Warning Fixed

pkg

35 / 49

Nitpicky Warnings/Notes

  • Title Case

  • Description period.

  • Fix license

  • Etc.

36 / 49

Check Warning Fixed

pkg

37 / 49

Install and Restart (cmd-shift-B)

pkg

38 / 49

Build Source

pkg

39 / 49

Build Source

pkg

40 / 49

Share with coworkers

  • Copy zipped source file to a common location

  • install.packages("path/to/source", repos = NULL)

41 / 49

Share with Strangers

pkg

42 / 49

Git Set!

pkg

43 / 49

Git Pane

pkg

44 / 49

Create Github Repo

repo

45 / 49

Initiate Github Repo

init

46 / 49

First Commit!

pkg

47 / 49

devtools::install_github

library(devtools)
devtools::install_github("joongsup/demor")
library(demor)
demor_ht(mtcars)
48 / 49

Thanks!

49 / 49

Motivation

library(ggplot2)
ggplot(data = mtcars) +
geom_bar(aes(x = factor(cyl), fill = factor(gear)))

2 / 49
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