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

My Organization's First R package

Teach your package

rstudio::conf(2020L)

1 / 30

2 / 30

Your Turn 1: Discussion

What do you do when you want to learn a new package?

3 / 30

Learning new packages

  1. Examples
  2. Vignettes/pkgdown
  3. README
  4. Blog posts
  5. Books
4 / 30

Learning new packages

  1. Examples
  2. Vignettes/pkgdown
  3. README
  4. Blog posts
  5. Books
5 / 30

Learning new packages

  1. Examples
  2. Vignettes/pkgdown
  3. README
  4. Blog posts
  5. Books
6 / 30

Guiding users

document scope
Vignettes User-friendly, deeper introductions and complex topics
README Simple introduction, installation. Get users going
Documentation
and examples
Granular, function-specific details and examples
7 / 30

Examples revisted

8 / 30

Examples revisted

If you don't want to run examples, wrap them in dontrun{} or donttest{}

#' [other roxygen code]
#' @examples
#'
#' dontrun{
#' get_data("daily_active_users")
#' }
get_data <- function(x) {
# code to get data
}
8 / 30

Examples revisted

Don't mess around with the user's directory. Use tempfile() or fs if you need to.

library(fs)
dir <- file_temp()
dir_create(dir)
9 / 30
create_package(path(dir, "temp.package"))
## ✔ Creating '/var/folders/03/9x7925g54mncswxx06wpkxl00000gn/...
## ✔ Setting active project to '/private/var/folders/03/9x7925...
## ✔ Creating 'R/'
## ✔ Writing 'DESCRIPTION'
## Package: temp.package
## Title: What the Package Does (One Line, Title Case)
## Version: 0.0.0.9000
## Authors@R (parsed):
## * Malcolm Barrett <malcolmbarrett@gmail.com> [aut, cre] (<https://orcid.org/0000-0003-0299-5825>)
## Description: What the package does (one paragraph).
## License: MIT + file LICENSE
## Encoding: UTF-8
## LazyData: true
## Roxygen: list(markdown = TRUE)
## ✔ Writing 'NAMESPACE'
## ✔ Writing 'temp.package.Rproj'
## ✔ Adding '.Rproj.user' to '.gitignore'
## ✔ Adding '^temp\\.package\\.Rproj$', '^\\.Rproj\\.user$' to...
## ✔ Opening '/var/folders/ 03/9x7925g54mncswxx06wpkxl00000gn/...
## ✔ Setting active project to '<no active project>'
10 / 30

Vignettes

11 / 30

Vignettes

Long-form documentation, written in R Markdown

11 / 30

Vignettes

Long-form documentation, written in R Markdown

Great for general introductions and complex topics you don't want buried in the documentation

12 / 30

Vignettes

Long-form documentation, written in R Markdown

Great for general introductions and complex topics you don't want buried in the documentation

Get rendered on pkgdown sites. See also use_article()

13 / 30

Vignettes

Long-form documentation, written in R Markdown

Great for general introductions and complex topics you don't want buried in the documentation

Get rendered on pkgdown sites. See also use_article()

use_vignette()

14 / 30

15 / 30

16 / 30

17 / 30

18 / 30

Need a Markdown refresher?

19 / 30

Need a Markdown refresher?

Interactive, 10-20 min tutorial: https://commonmark.org/help/tutorial/

19 / 30

Need a Markdown refresher?

Interactive, 10-20 min tutorial: https://commonmark.org/help/tutorial/

The R Markdown website or book

19 / 30

Your Turn 2

Open vignettes/intro-to-avalanchr.Rmd.

Let's add some more content before we knit this vignette. Lines 27-29 have an R Markdown code chunk. On line 28, fill in the blank with this code: db_con("residents_per_sector")

Let's also add some examples of the summarizing and plotting functions. On line 57, fill in the blank with count_donations(). On line 62, use plot_donations()

Knit the vignette. If you're having trouble finding some of your functions, try re-loading or documenting and re-building.

20 / 30

README

21 / 30

README

A quick overview of your package

21 / 30

README

A quick overview of your package

A good place for installation instructions

22 / 30

README

A quick overview of your package

A good place for installation instructions

Becomes the homepage for a pkgdown site

23 / 30

README

A quick overview of your package

A good place for installation instructions

Becomes the homepage for a pkgdown site

use_readme_md() or use_readme_rmd()

24 / 30

What should I put in the README?

  1. Badges (?use_badge()), where applicable.
  2. Installation instructions
  3. A few examples
  4. Maybe: how to contribute (use_tidy_contributing())
25 / 30

R Packages: ggplot2's README

26 / 30

27 / 30

Your Turn 3

Run use_readme_rmd() to setup a README. Knit the file and take a look.

Let's add some badges. Run use_lifecycle_badge("experimental") and use_cran_badge(). Then, re-knit.

29 / 30

Spell check with the spelling package

use_spell_check()

30 / 30

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