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

My Organization's First R package

Setup R Packages

rstudio::conf(2020L)

1 / 45

2 / 45

devtools

3 / 45

devtools

Tools to make an R developer's life easier

Well be using functions like load_all(), build(), document(), test(), and check() throughout the day.

3 / 45

usethis

4 / 45

usethis

Set up commonly used 📦 components

Well be using functions like create_package(), use_r(), use_test(), and many more throughout the day.

4 / 45

shinRa

An R package for the data science team at the Shinra Electric Power Company, also known as Shinra, Inc.

What will it do? Custom ggplot2 themes, reports, data connections and filtering, and more.

5 / 45

create_package("shinRa")

library(usethis)
create_package("shinRa")
6 / 45
library(usethis)
create_package("shinRa")
## ✔ Creating '/var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T/Rtmp7tPPPb/file7084271a9342/shinRa/'
## ✔ Setting active project to '/private/var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T/Rtmp7tPP...
## ✔ Creating 'R/'
## ✔ Writing 'DESCRIPTION'
## Package: shinRa
## Title: What the Package Does (One Line, Title Case)
## Version: 0.0.0.9000
## Authors@R (parsed):
## * First Last <first.last@example.com> [aut, cre] (<https://orcid.org/YOUR-ORCID-ID>)
## Description: What the package does (one paragraph).
## License: `use_mit_license()`, `use_gpl3_license()` or friends to pick a
## license
## Encoding: UTF-8
## LazyData: true
## Roxygen: list(markdown = TRUE)
## ✔ Writing 'NAMESPACE'
## ✔ Writing 'shinRa.Rproj'
## ✔ Adding '.Rproj.user' to '.gitignore'
## ✔ Adding '^shinRa\ \.Rproj$', '^\\.Rproj\\.user$' to '.Rbuildignore'
## ✔ Setting active project to '/private/var/folders/ 03/9x7925g54mncswxx06wpkxl00000gn/T/Rtmp7tP...
## /var/folders/03/9x7925g54mncswxx06wpkxl00000gn/T//Rtmp7tPPPb/file7084271a9342/shinRa
7 / 45

8 / 45

9 / 45

10 / 45

11 / 45

12 / 45

13 / 45

Your Turn 1

Load usethis and devtools if you haven't.

Open the DESCRIPTION file and take a look. It's very generic!

Run edit_r_profile(). Copy and paste this code into your R profile, but change it to your name and email. If you would like to add your ORCID ID see ?use_description for an example for an example that includes that.

Then, restart your R session (Session > Restart R).

if you don't want to change your R profile, you can just run the code in the console without running edit_r_profile() or restarting

When you've restarted, run use_description() to replace the DESCRIPTION file.

Open the DESCRIPTION file and take a look around.

14 / 45

Your Turn 1: Stretch Goal

15 / 45

avalanchr

An R package for the data science team for the AVALANCHE ecological insurgency organization.

16 / 45

17 / 45

18 / 45

Valid package names:

  1. Consist of letters, numbers, or periods.
  2. Start with a letter.
  3. Do not end with a period
19 / 45

Use the available package to check your package name

20 / 45

Naming your package

available::suggest("Shinra Electric Power")
## shinrar
21 / 45

Naming your package

available::suggest("Shinra Electric Power")
## shinrar

Also see "Naming Things"

21 / 45

Is the name available?

available::available("package.name")
22 / 45

Is the name available?

available::available("package.name")

Image from the available repository

22 / 45

23 / 45

image from R Packages, ed. 2

24 / 45

25 / 45

Adding an author with desc

26 / 45

Adding an author with desc

desc::desc_add_author(
given = "Rufus",
family = "Shinra",
role = "ctb",
email = "rufus@shinrainc.com",
comment = list("ORCID-ID" = "902348-439034")
)
26 / 45

Adding an author with desc

desc::desc_add_author(
given = "Rufus",
family = "Shinra",
role = "ctb",
email = "rufus@shinrainc.com",
comment = list("ORCID-ID" = "902348-439034")
)
27 / 45

Adding an author with desc

desc::desc_add_author(
given = "Rufus",
family = "Shinra",
role = "ctb",
email = "rufus@shinrainc.com",
comment = list("ORCID-ID" = "902348-439034")
)
28 / 45

Adding an author with desc

desc::desc_add_author(
given = "Rufus",
family = "Shinra",
role = "ctb",
email = "rufus@shinrainc.com",
comment = list("ORCID-ID" = "902348-439034")
)
29 / 45

R package roles

Code Role
cre Maintainer
aut Author
ctb Contributer
cph Copyright-holder

Full list: http://www.loc.gov/marc/relators/relaterm.html

30 / 45

Your Turn 2

Add a new author to avalanchr using desc::desc_add_author(). Set given to "Barret", family to "Wallace", and role to "aut".

In DESCRIPTION, change the title to "Tools for the Avalanche Data Science Team"

Change the Description field to "A set of tools to use within the Avalance Data Science team. This package contains functions for connecting to data bases, R markdown templates, ggplot2 themes, and more."

Run use_tidy_description() to clean up the file.

31 / 45

32 / 45

use_*_licence()

33 / 45

use_*_licence()

use_mit_license("Company Name"). Check the help page for more.

33 / 45

use_*_licence()

use_mit_license("Company Name"). Check the help page for more.

Help with open-source licenses: https://choosealicense.com/

Help with proprietary licenses: http://www.binpress.com/license-generator/

34 / 45

Proprietary licenses

Put this in your DESCRIPTION file:

License: file LICENSE
35 / 45

Proprietary licenses

Put this in your DESCRIPTION file:

License: file LICENSE



Put this in your LICENSE file:

Proprietary
Do not distribute outside of Shinra, Inc.



35 / 45

Proprietary licenses

Put this in your DESCRIPTION file:

License: file LICENSE



Put this in your LICENSE file:

Proprietary
Do not distribute outside of Shinra, Inc.



35 / 45

Your Turn 3

Run use_mit_license("AVALANCHE"). What changed?

36 / 45

Your Turn 3: Stretch Goal

Change the license to use the proprietary license above.

37 / 45

38 / 45

39 / 45

40 / 45

Setting up git and GitHub

41 / 45

Setting up git and GitHub

use_git(), use_github()

42 / 45

Setting up git and GitHub

use_git(), use_github()

create_from_github() to clone

43 / 45

Setting up git and GitHub

use_git(), use_github()

create_from_github() to clone

pr_init() and friends to do pull requests

44 / 45

Setting up git and GitHub

use_git(), use_github()

create_from_github() to clone

pr_init() and friends to do pull requests

Other usethis functions for setting up GitHub, e.g. labels, issues, contributing guidelines, etc

45 / 45

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