background-image: url(https://i.imgur.com/CVIZGyY.jpg) background-position: top background-size: 100% class: inverse, shadow # My Organization's First R package ## Teach your package ## `rstudio::conf(2020L)` --- class: middle, center <img src="img/where_are_we_05.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- ## Your Turn 1: Discussion ## What do you do when you want to learn a new package? --- class: inverse # Learning new packages 1. Examples 1. Vignettes/pkgdown 1. README 1. Blog posts 1. Books --- class: inverse # Learning new packages 1. **Examples** 1. Vignettes/pkgdown 1. README 1. Blog posts 1. Books --- class: inverse # Learning new packages 1. Examples 1. **Vignettes/pkgdown** 1. **README** 1. Blog posts 1. Books --- class: center, middle # Guiding users | document | scope| |--:|--:| | Vignettes | User-friendly, deeper introductions and complex topics | | README | Simple introduction, installation. Get users going | | Documentation <br>and examples | Granular, function-specific details and examples | --- # Examples revisted -- ## If you don't want to run examples, wrap them in `dontrun{}` or `donttest{}` ```r #' [other roxygen code] #' @examples #' *#' dontrun{ *#' get_data("daily_active_users") *#' } get_data <- function(x) { # code to get data } ``` --- # Examples revisted ## Don't mess around with the user's directory. Use `tempfile()` or fs if you need to. ```r library(fs) dir <- file_temp() dir_create(dir) ``` --- ```r 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>'``` --- # Vignettes -- ## Long-form documentation, written in [R Markdown](https://rmarkdown.rstudio.com/) --- # Vignettes ## ~~Long-form documentation, written in R Markdown~~ ## Great for general introductions and complex topics you don't want buried in the documentation --- # 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()` --- # 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()` --- <img src="img/checkpoint_vignette.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/use_vignette_yaml.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/use_vignette_yaml_title.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- <img src="img/use_vignette_yaml_output.png" width="100%" height="100%" style="display: block; margin: auto;" /> --- # Need a Markdown refresher? -- ## Interactive, 10-20 min tutorial: https://commonmark.org/help/tutorial/ -- ## The R Markdown [website](https://rmarkdown.rstudio.com/) or [book](https://bookdown.org/yihui/rmarkdown/) --- ## 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. --- # README -- ## **A quick overview of your package** --- # README ## ~~A quick overview of your package~~ ## **A good place for installation instructions** --- # README ## ~~A quick overview of your package~~ ## ~~A good place for installation instructions~~ ## **Becomes the homepage for a pkgdown site** --- # 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()`* --- class: inverse # 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()`) --- .pull-left[ ## R Packages: [ggplot2's README](https://github.com/tidyverse/ggplot2) ] .pull-right[ <img src="img/readme_ggplot2.png" width="100%" height="100%" style="display: block; margin: auto;" /> ] --- .pull-left[ ## Other READMEs: [Zhi Yang's TidyTuesday repo](https://github.com/zhiiiyang/tidytuesday) ] .pull-right[ <img src="img/readme_zhi.png" width="100%" height="100%" style="display: block; margin: auto;" /> ] --- .pull-left[ ## Other READMEs: [Zhi Yang's TidyTuesday repo](https://github.com/zhiiiyang/tidytuesday) ## Check out ["Building a Better README"](https://blog.sourcerer.io/building-a-better-readme-d5053a7bc341) ] .pull-right[ <img src="img/readme_zhi.png" width="100%" height="100%" style="display: block; margin: auto;" /> ] --- ## 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. --- # Spell check with the [spelling](https://docs.ropensci.org/spelling/) package ## `use_spell_check()`