(PART) Create an R package {.unnumbered}

Create an R package

Creating an R package can be done in a few easy steps.

library(devtools)
library(usethis)
usethis::create_package("~/Documents/GitHub/MyExamplePackage")
usethis::use_mit_license("J Kyle Armstrong")
usethis::use_readme_md()
usethis::use_pkgdown()
usethis::use_testthat()
usethis::use_package("ggplot2", "Imports", min_version = TRUE)
tidyverse_packages <- c('tibble','readr','dplyr','tidyr','stringr','purrr','ggplot2','forcats')

tidyverse_friends <- c('broom','lubridate','readxl','knitr','shiny','furrr','flexdashboard','yardstick')

other_packages <- c('devtools','rsq','arsenal','skimr',
                    'RSQLite','dbplyr','plotly','DT','GGally','corrr',
                    'AMR','caret','shiny','DataExplorer','randomForest','usethis','testthat','pkgdown')

purrr::walk(c(tidyverse_packages, tidyverse_friends, other_packages),
function(package){
usethis::use_package(package, "Imports", min_version = TRUE)
}
)
devtools::load_all()
devtools::document()
devtools::install()
detach(package:MyExamplePackage)

How to Organize and Run Your Tests

We should have a folder named R with all the R code, and one folder named tests/testthat, where all the test scripts will live. For each file with R scripts there should be another one with tests, with the same name, but prefixed by test-, as shown:

library(testthat)
library(MyExamplePackage)

devtools::test()

Build package site

pkgdown::build_site()


jkylearmstrong/MyExamplePackage documentation built on April 15, 2022, 1:14 a.m.