📦
Building tidy tools

Day 1 Session 1: 👋 & The Whole Game

Emma Rand and Ian Lyttle

Invalid Date

👋 Welcome

Introductions

This is a two-day, hands-on workshop for those who have embraced the tidyverse and want to build their own packages.

  • Have you written a few of your own R functions?
  • Are you ready to start sharing your code (or data) through R packages?
  • Are you curious what you can do to make your first R packages easy for your users to use, and for you to maintain?


WiFi

  • Username: conf22
  • Password: together!

The team

Emma Rand 🐦@er13_r

Elliot Murphy

Kailey Mulligan

Beatriz Milz 🐦@BeaMilz

Ian Lyttle 🐦@ijlyttle

Haley Jeppson

Ted Laderas 🐦@tladeras

 

Standing on the shoulders of Building Tidy Tools, rstudio::conf(2020) (C. Wickham and Wickham 2021), R Packages (H. Wickham and Bryan 2020)


WiFi

  • Username: conf22
  • Password: together!

Introductions

To each other! With help from Yorkshire!

Ingredients: Sugar, Glucose syrup, Cocoa mass, Vegetable fats (Palm, Rapeseed, Sunflower, Coconut,Mango kernel/ Sal/ Shea), Sweetened condensed skimmed milk (Skimmed milk, Sugar), Cocoa butter, Dried whole milk, Glucose-fructose syrup, Coconut, Lactose and proteins from whey (from Milk), Whey powder (from Milk), Hazelnuts, Skimmed milk powder, Butter (from Milk), Emulsifiers (Sunflower lecithin, E471), Flavourings, Butterfat (from Milk), Fat-reduced cocoa powder, Salt, Lactic acid.

Ingredients: Sugar, Semi-Sweet Chocolate (Sugar, Chocolate, Cocoa Butter, Milkfat, Soy and Sunflower Lecithin, Natural Vanilla Flavor), Glucose Syrup, Peppermint Oil, Citric Acid, Invertase.

Ingredients: Sugar, Glucose Syrup, Starch, Acids (Malic Acid, Citric Acid, Lactic Acid), Concentrated Fruit Juices (1%) (Apple, Grape, Blackcurrant, Orange, Lemon, Lime, Strawberry), Acidity Regulator (Trisodium Citrate), Flavourings, Naturally Sourced Colours (Anthocyanins, Copper Complexes of Chlorophyllins, Carotenes, Curcumin).

Code of Conduct

Full Code of Conduct & COVID. Please Review

  • 😷 Please wear a mask
  • 💙 Treat everyone with respect
  • 🧡 Everyone should feel welcome

Reporting:

  • 🗣️ any rstudio::conf staff member, Elliot is our contact
  • 📧 conf@rstudio.com
  • ☎️ + 1 844-448-1212

Housekeeping

  • WiFi:
    • Username: conf22
    • Password: together!
  • Gender neutral bathrooms by the National Harbor rooms.
  • The meditation room is at National Harbor 9. Open 8am - 5pm, Monday - Thursday. The hotel also has a dedicated room behind the reception.
  • The lactation room is located at Potomac Dressing Room. Open 8am - 5pm, Monday - Thursday.
  • Participants who do not wish to be photographed have red lanyards, please note lanyard colors before taking a photo and respect their choices.

🙏 to

  • the TAs

  • colleagues, friends and learners at Schneider Electric, University of York and RForwards!

  • RStudio team and especially Mine Çetinkaya-Rundel

  • Ian!

Prerequisites

You need a laptop with the following installed:

  • R version >= 4.1 and RStudio >= 2022.02.1
  • R package development toolchain: Rtools(windows) or XCode (mac) or r-base-dev
  • The following packages: devtools and btt22
  • Git
  • GitHub account linked to RStudio

🎬 Detailed instructions for installing these are covered in Prerequisites

Day 1

Time Activity
09:00 - 10:30 Session 1: Introduction & whole game
10:30 - 11:00 Coffee break
11:00 - 12:30 Session 2: Documentation - Minimal
12:30 - 13:30 🍱 Lunch break
13:30 - 15:00 Session 3: Unit testing
15:00 - 15:30 Coffee break
15:30 - 17:00 Session 4: Documentation - Sharing

Day 2

Time Activity
09:00 - 10:30 Session 1: Function design
10:30 - 11:00 Coffee break
11:00 - 12:30 Session 2: Side effects
12:30 - 13:30 🍱 Lunch break
13:30 - 15:00 Session 3: Tidy eval
15:00 - 15:30 Coffee break
15:30 - 17:00 Session 4: Functional and Object-Oriented Programming

How we will work

  • stickies

    • 🟪 I’m all good, I’m done

    • 🟧 I could do with some help

  • Discord

  • no stupid questions

  • 🎬 Action! (today)

Learning Objectives

At the end of this section you will be able to:

  • Make changes to your .Rprofile and RStudio set to ease the package writing process
  • explain the rationale for writing packages
  • find and explore their own package library/libraries
  • describe the key components of a minimal package
  • describe the different states a package can be in
  • outline the development of a package using devtools (H. Wickham et al. 2021)
  • create a simple version controlled package with a remote repo on GitHub
  • use the package interactively with devtools::load_all()
  • check package validity with devtools::check()

🔥 Set up tips

🔥 Global Options

🎬 Tools | Global Options | General


🔲 Restore .RData into workspace at startup: unchecked

Save workspace to .RData on exit: Never


🎬 Tools | Global Options | Code | Display


☑️ Show margin: checked

Margin column 80

🔥 Set up your .Rprofile

The usethis (H. Wickham, Bryan, and Barrett 2022) package allows you to add default information about you that will be used in package development.


🎬 Edit your .Rprofile with usethis::edit_r_profile:

usethis::edit_r_profile()


to set the following options….

🔥 Set up your .Rprofile

options(
  usethis.full_name = "Emma Rand",
  usethis.description = list(
    `Authors@R` = 'person("Emma", "Rand",
          email = "emma.rand@york.ac.uk",
          role = c("aut", "cre"))'
  )
)

🔥 Set up your .Rprofile

🎬 Load devtools and testthat (H. Wickham 2011) on start up



🎬 Restart R for these to take an effect.

Why make a package?

Why make a package

  • makes it easier to reuse functions you write
  • have a consistent framework which encourages you to better organise, document and test, your code
  • using this consistent framework means you can use many standardised tools
  • is the easiest way to distribute code and data

Be nice to future you

Person working at a computer with an offstage person asking "How is the analysis going?" The person at the computer replies "Can't understand the data...and the data collector does not answer my emails or calls" Person offstage: "That's terrible! So cruel! Who did collect the data? I will sack them!" Person at the computer: "um...I did, 3 years ago"

Future self: CC-BY-NC, by Julen Colomb, derived from Randall Munroe cartoon

To avoid

via GIPHY

Script vs package

Script

  • one-off data analysis
  • defined by .R extension
  • library() calls
  • documentation in # comments
  • source()

Package

  • defines reusable components
  • defined by presence of DESCRIPTION file
  • Required packages specified in DESCRIPTION, made available in NAMESPACE file
  • documentation in files and Roxygen comments
  • Install and restart

Where packages come from and live?

Where do R packages come from?

CRAN:

GitHub:

remotes::install_github("rladies/praise")

Bioconductor

BiocManager::install("celaref")

Where do packages live?

In a library! In

[1] "/opt/R/4.2.2/lib/R"

The R home directory is the top-level directory of your R installation.

Note: this is not the same as your working directory or your home directory.

Your R installation

 [1] "bin"          "COPYING"      "doc"          "etc"          "include"     
 [6] "lib"          "library"      "modules"      "share"        "SVN-REVISION"

Your library

.Library
[1] "/opt/R/4.2.2/lib/R/library"

Your library

dir(.Library)
 [1] "base"         "boot"         "class"        "cluster"      "codetools"   
 [6] "compiler"     "datasets"     "foreign"      "graphics"     "grDevices"   
[11] "grid"         "KernSmooth"   "lattice"      "MASS"         "Matrix"      
[16] "methods"      "mgcv"         "nlme"         "nnet"         "parallel"    
[21] "rpart"        "spatial"      "splines"      "stats"        "stats4"      
[26] "survival"     "tcltk"        "tools"        "translations" "utils"       

Explore a package

The ussie package

  • We will create a version controlled package called ussie with a remote repo on GitHub.


ussie will allow you to work with European football league data supplied by the engsoccerdata package (Curley 2016).

Explore ussie


GitHub is the package in “Source” form

  • main code in R/
  • documentation files in man/ and vignettes/
  • DESCRIPTION

Package states

Package states

There are five states a package can be in:

  • source

  • bundled

  • binary

  • installed

  • in-memory

Package states

schematic of package states and the functions that move them between states. One the horizontal axis: source, bundle, binary, installed, in memory. One the vertical axis the functions install.packages, R CMD install, install, build, install_github

Schematic of methods for moving between package states

Package states

  • source

  • bundled

  • binary

  • installed

  • in-memory

What you create and work on.

Specific directory structure with some particular components e.g., DESCRIPTION, an R/ directory.

Package states

  • source

  • bundled

  • binary

  • installed

  • in-memory

Also known as “source tarballs”.

Package files compressed to single file.

Conventionally .tar.gz

You don’t normally need to make one.

Unpacked it looks very like the source package

Package states

  • source

  • bundled

  • binary

  • installed

  • in-memory

Package distribution for users w/o dev tools

Also a single file

Platform specific: .tgz (Mac) .zip (Windows)

Package developers submit a bundle to CRAN; CRAN makes and distributes binaries

install.packages()

Package states

  • source

  • bundled

  • binary

  • installed

  • in-memory

A binary package that’s been decompressed into a package library

Command line tool R CMD INSTALL powers all package installation

Package states

  • source

  • bundled

  • binary

  • installed

  • in-memory

If a package is installed, library() makes its function available by loading the package into memory and attaching it to the search path.

We do not use library() for packages we are working on

devtools::load_all() loads a source package directly into memory.

Create a package!

Create a package

The CRAN version of engsoccerdata has data from the start of the league until 2016 for england, germany, holland, italy and spain


BUT the format of the data is not the same for all countries!!

About engsoccerdata

dplyr::glimpse(engsoccerdata::england)
Rows: 192,004
Columns: 12
$ Date     <fct> 1888-12-15, 1889-01-19, 1889-03-23, 1888-12-01, 1888-10-13, 1…
$ Season   <dbl> 1888, 1888, 1888, 1888, 1888, 1888, 1888, 1888, 1888, 1888, 1…
$ home     <fct> Accrington F.C., Accrington F.C., Accrington F.C., Accrington…
$ visitor  <fct> Aston Villa, Blackburn Rovers, Bolton Wanderers, Burnley, Der…
$ FT       <fct> 1-1, 0-2, 2-3, 5-1, 6-2, 3-1, 1-2, 0-0, 2-0, 2-1, 4-4, 4-3, 6…
$ hgoal    <dbl> 1, 0, 2, 5, 6, 3, 1, 0, 2, 2, 4, 4, 6, 6, 4, 4, 2, 9, 0, 5, 2…
$ vgoal    <dbl> 1, 2, 3, 1, 2, 1, 2, 0, 0, 1, 4, 3, 1, 2, 2, 2, 1, 1, 2, 1, 0…
$ division <fct> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
$ tier     <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1…
$ totgoal  <dbl> 2, 2, 5, 6, 8, 4, 3, 0, 2, 3, 8, 7, 7, 8, 6, 6, 3, 10, 2, 6, …
$ goaldif  <dbl> 0, -2, -1, 4, 4, 2, -1, 0, 2, 1, 0, 1, 5, 4, 2, 2, 1, 8, -2, …
$ result   <fct> D, A, A, H, H, H, A, D, H, H, D, H, H, H, H, H, H, H, A, H, H…
dplyr::glimpse(engsoccerdata::spain)
Rows: 23,915
Columns: 12
$ Date    <chr> "1929-02-10", "1929-02-10", "1929-02-10", "1929-02-10", "1929-…
$ Season  <dbl> 1928, 1928, 1928, 1928, 1928, 1928, 1928, 1928, 1928, 1928, 19…
$ home    <chr> "Arenas de Getxo", "Espanyol Barcelona", "Real Madrid", "Real …
$ visitor <chr> "Atletico Madrid", "Real Union", "CE Europa", "Athletic Bilbao…
$ HT      <chr> "0-2", "1-0", "0-0", "1-1", "0-0", "0-1", "3-0", "0-3", "0-1",…
$ FT      <chr> "2-3", "3-2", "5-0", "1-1", "0-2", "1-2", "9-0", "0-3", "3-1",…
$ hgoal   <dbl> 2, 3, 5, 1, 0, 1, 9, 0, 3, 5, 3, 3, 1, 0, 2, 1, 2, 3, 2, 2, 3,…
$ vgoal   <dbl> 3, 2, 0, 1, 2, 2, 0, 3, 1, 2, 0, 1, 1, 4, 1, 2, 1, 0, 2, 0, 3,…
$ tier    <dbl> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
$ round   <chr> "league", "league", "league", "league", "league", "league", "l…
$ group   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…
$ notes   <chr> NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA, NA…

First function

So the first function in our ussie package will turn these in to standard formats:

  • use only the common columns

  • give the same column the same data type

Create a package

Be deliberate about where you create your package

Do not nest inside another RStudio project, R package or git repo.


🎬 Create a package:

usethis::create_package("~/Desktop/ussie")

✔ Creating 'ussie/'
✔ Setting active project to 'C:/Users/er13/OneDrive - University of York/Desktop/Desktop/rstudio-conf-2022/ussie'
✔ Creating 'R/'
✔ Writing 'DESCRIPTION'
Package: ussie
Title: What the Package Does (One Line, Title Case)
Version: 0.0.0.9000
Authors@R (parsed):
    * Emma Rand <emma.rand@york.ac.uk> [aut, cre] (<https://orcid.org/0000-0002-1358-8275>)
Description: What the package does (one paragraph).
License: `use_mit_license()`, `use_gpl3_license()` or friends to
    pick a license
Encoding: UTF-8
Roxygen: list(markdown = TRUE)
RoxygenNote: 7.2.0
✔ Writing 'NAMESPACE'
✔ Writing 'ussie.Rproj'
✔ Adding '^ussie\\.Rproj$' to '.Rbuildignore'
✔ Adding '.Rproj.user' to '.gitignore'
✔ Adding '^\\.Rproj\\.user$' to '.Rbuildignore'
✔ Opening 'C:/Users/er13/OneDrive - University of York/Desktop/Desktop/rstudio-conf-2022/ussie/' in new RStudio session
✔ Setting active project to '<no active project>'

create_package()

What happens when we run create_package()?

  • R will create a folder called ussie which is a package and an RStudio project

  • restart R in the new project

  • create some infrastructure for your package

  • start the RStudio Build pane

create_package()

What happens when we run create_package()?

  • ussie.Rproj

  • DESCRIPTION provides metadata about your package.

  • The R/ directory is where we will put .R files with function definitions.

  • NAMESPACE declares the functions your package exports and the functions your package imports from other packages.

create_package()

What happens when we run create_package()?

  • .Rbuildignore lists files that we need but that should not be included when building the R package from source.

  • .gitignore anticipates Git usage and ignores some standard, behind-the-scenes files created by R and RStudio.

Make package a git repo

🎬 Make your package a git repository

usethis::use_git()

✔ Setting active project to 'C:/Users/er13/OneDrive - University of York/Desktop/Desktop/rstudio-conf-2022/ussie'
✔ Initialising Git repo
✔ Adding '.Rhistory', '.Rdata', '.httr-oauth', '.DS_Store' to '.gitignore'
There are 5 uncommitted files:
* '.gitignore'
* '.Rbuildignore'
* 'DESCRIPTION'
* 'NAMESPACE'
* 'ussie.Rproj'
Is it ok to commit them?

1: No way
2: Negative
3: I agree


🎬 Choose the option that means yes!

✔ Adding files
✔ Making a commit with message 'Initial commit'
• A restart of RStudio is required to activate the Git pane
Restart now?

1: Yup
2: Not now
3: Absolutely not


🎬 Choose the option that means yes!


Your session will restart.

Put a remote copy on GitHub

🎬 Put on GitHub as a remote repository

usethis::use_github()

ℹ Defaulting to 'https' Git protocol
✔ Setting active project to 'C:/Users/er13/OneDrive - University of York/Desktop/Desktop/rstudio-conf-2022/ussie'
✔ Creating GitHub repository '3mmaRand/ussie'
✔ Setting remote 'origin' to 'https://github.com/3mmaRand/ussie.git'
✔ Setting URL field in DESCRIPTION to 'https://github.com/3mmaRand/ussie'
✔ Setting BugReports field in DESCRIPTION to 'https://github.com/3mmaRand/ussie/issues'
There is 1 uncommitted file:
* 'DESCRIPTION'
Is it ok to commit it?

1: Absolutely
2: Nope
3: No

🎬 Choose the option that means yes!

✔ Adding files
✔ Making a commit with message 'Add GitHub links to DESCRIPTION'
✔ Pushing 'main' branch to GitHub and setting 'origin/main' as upstream branch
✔ Opening URL 'https://github.com/3mmaRand/ussie'

🎬 Quick check with:

usethis::git_sitrep()
Git config (global)
• Name: 'Emma Rand'
• Email: 'emma.rand@york.ac.uk'
• Global (user-level) gitignore file: 'C:/Users/er13/.gitignore'
• Vaccinated: TRUE
• Default Git protocol: 'https'
• Default initial branch name: 'master', 'main'
GitHub
• Default GitHub host: 'https://github.com'
• Personal access token for 'https://github.com': '<discovered>'
• GitHub user: '3mmaRand'
• Token scopes: 'gist, repo, user, workflow'
• Email(s): 'emma.rand@york.ac.uk (primary)', '7593411+3mmaRand@users.noreply.github.com'
Git repo for current project
• Active usethis project: 'C:/Users/er13/OneDrive - University of York/Desktop/Desktop/rstudio-conf-2022/ussie'
• Default branch: 'main'
• Current local branch -> remote tracking branch:
  'main' -> 'origin/main'
GitHub remote configuration
• Type = 'ours'
• Host = 'https://github.com'
• Config supports a pull request = TRUE
• origin = '3mmaRand/ussie' (can push)
• upstream = <not configured>
• Desc = 'origin' is both the source and primary repo.
  
  Read more about the GitHub remote configurations that usethis supports at:
  'https://happygitwithr.com/common-remote-setups.html'

Add the first function

We will add uss_make_matches()

Functions will go in an .R file.


There’s a usethis helper for adding .R files!


usethis::use_r("file_name")


usethis::use_r() adds the file extension and saves in R/ folder

usethis::use_r()

🎬 Create a new R file in your package called matches.R


usethis::use_r("matches")
• Modify 'R/matches.R'
• Call `use_test()` to create a matching test file

The function?

We want to be able to use the function like this: uss_make_matches(engsoccerdata::italy)

Add the function

🎬 Put the following code into matches:

uss_make_matches <- function(data_engsoc) {
  result <-
    data_engsoc |>
    tibble::as_tibble() |>
    dplyr::transmute(
      tier = factor(tier, levels = c("1", "2", "3", "4")),
      season = as.integer(Season),
      date = as.Date(Date),
      home = as.character(home),
      visitor = as.character(visitor),
      goals_home = as.integer(hgoal),
      goals_visitor = as.integer(vgoal)
    )
  result
}

Try out your function

Development workflow

In a normal script you might use:

source("R/matches.R")


but when building packages we use a devtools approach

Development workflow

%%{init: {'theme': 'base', 'themeVariables': { 'primaryColor': '#f3f3f3',  'lineColor':'#EE9AD9'}}}%%

  flowchart LR
      id1("Load code: \n load_all()") --> 
      id2("Explore in \n console") --> 
      id3("Modify \n code")
      id3 --> id1
      style id1 id2 id3 stroke:#3F3F3F,stroke-width:2px

Load your package

devtools::load_all()

🎬 Load package with devtools::load_all().

devtools::load_all()
ℹ Loading ussie

Experiment

🎬 Try out the uss_make_matches() function in the console.

uss_make_matches(engsoccerdata::italy)
# A tibble: 25,404 × 7
    tier season date       home   visitor goals_home goals_visitor
   <int>  <int> <date>     <chr>  <chr>        <int>         <int>
 1     1   1934 1934-09-30 Lazio… US Liv…          6             1
 2     1   1934 1934-09-30 Torin… Unione…          3             1
 3     1   1934 1934-09-30 Sampi… Bologn…          2             1
 4     1   1934 1934-09-30 SSC N… US Ale…          0             1
 5     1   1934 1934-09-30 ACF F… AS Roma          4             1
 6     1   1934 1934-09-30 Bresc… Juvent…          0             2
 7     1   1934 1934-09-30 Inter  US Pal…          3             0
 8     1   1934 1934-09-30 Pro V… AC Mil…          1             2
 9     1   1934 1934-10-07 AC Mi… ACF Fi…          1             1
10     1   1934 1934-10-07 US Li… Inter            1             1
# … with 25,394 more rows

🤔 There’s no column for the country - that could be confusing

Update the function

🎬 Change the function so it takes an additional argument which is the name of the country. The country name should be in column called “country”. The aim is to use the function like this:

uss_make_matches(engsoccerdata::spain, "Spain")


🎬 Load with devtools::load_all() and try out the updated function.

An answer

uss_make_matches <- function(data_engsoc, country) {
  result <-
    data_engsoc |>
    tibble::as_tibble() |>
    dplyr::transmute(
      country = as.character(country),
      tier = factor(tier, levels = c("1", "2", "3", "4")),
      season = as.integer(Season),
      date = as.Date(Date),
      home = as.character(home),
      visitor = as.character(visitor),
      goals_home = as.integer(hgoal),
      goals_visitor = as.integer(vgoal)
    )
  result
}

Commit and push

Now would be a good time to commit your changes and push them to GitHub

Git iconGitHub icon

Check your package

Check your package

R CMD check is the gold standard for checking that an R package is in full working order.


It is a programme that is executed in the shell.


However, devtools has the check() function to allow you to run this without leaving your R session.

devtools::check()

🎬 Check your package:

devtools::check()

── R CMD check results ───────────────────────────────────── ussie 0.0.0.9000 ────
Duration: 25.1s

❯ checking DESCRIPTION meta-information ... WARNING
  Non-standard license specification:
    `use_mit_license()`, `use_gpl3_license()` or friends to pick a
    license
  Standardizable: FALSE

❯ checking dependencies in R code ... WARNING
  '::' or ':::' imports not declared from:
    'dplyr' 'tibble'

❯ checking R code for possible problems ... NOTE
  uss_make_matches: no visible binding for global variable 'tier'
  uss_make_matches: no visible binding for global variable 'Season'
  uss_make_matches: no visible binding for global variable 'Date'
  uss_make_matches: no visible binding for global variable 'home'
  uss_make_matches: no visible binding for global variable 'visitor'
  uss_make_matches: no visible binding for global variable 'hgoal'
  uss_make_matches: no visible binding for global variable 'vgoal'
  Undefined global functions or variables:
    Date Season hgoal home tier vgoal visitor

0 errors ✔ | 2 warnings ✖ | 1 note ✖


man/ is created

Aside: in case of error

On running devtools::check() you may get an error if you are using a networked drive.

Updating ussie documentation  
Error: The specified file is not readable: path-to\ussie\NAMESPACE


This is covered here and can be fixed.

Aside: in case of error

Save a copy of this file:

fix_for_networked_drives.R

Save it somewhere other than the ussie directory

Open the file from the ussie project session

Run the whole file

You should now find that check() proceeds normally

── R CMD check results ───────────────────────────────────── ussie 0.0.0.9000 ────
Duration: 25.1s

❯ checking DESCRIPTION meta-information ... WARNING
  Non-standard license specification:
    `use_mit_license()`, `use_gpl3_license()` or friends to pick a
    license
  Standardizable: FALSE

❯ checking dependencies in R code ... WARNING
  '::' or ':::' imports not declared from:
    'dplyr' 'tibble'

❯ checking R code for possible problems ... NOTE
  uss_make_matches: no visible binding for global variable 'tier'
  uss_make_matches: no visible binding for global variable 'Season'
  uss_make_matches: no visible binding for global variable 'Date'
  uss_make_matches: no visible binding for global variable 'home'
  uss_make_matches: no visible binding for global variable 'visitor'
  uss_make_matches: no visible binding for global variable 'hgoal'
  uss_make_matches: no visible binding for global variable 'vgoal'
  Undefined global functions or variables:
    Date Season hgoal home tier vgoal visitor

0 errors ✔ | 2 warnings ✖ | 1 note ✖

0 errors v | 2 warnings x | 1 note x

  • checking DESCRIPTION meta-information … WARNING
    Non-standard license specification
    ✅ Next!

  • checking dependencies in R code … WARNING
    ‘::’ or ‘:::’ imports not declared
    ✅ Next!

  • no visible binding for global variables
    ✅ Tomorrow!

License

Add a license

usethis helps out again!


use_mit_license(), use_agpl_license(), use_ccby_license() etc

🎬 Add a MIT license1 - use your own name!

usethis::use_mit_license("Emma Rand") 

Read more in Choose a Licence.

✔ Setting License field in DESCRIPTION to 'MIT + file LICENSE'
✔ Writing 'LICENSE'
✔ Writing 'LICENSE.md'
✔ Adding '^LICENSE\\.md$' to '.Rbuildignore'

use_mit_license()

🎬 What files have appeared?


🎬 How has the DESCRIPTION file changed?


🎬 Run devtools::check() again. Has one of the warnings disappeared?

📦 Woo hoo📦
You made a package!

Commit and push

Now would be a good time to commit your changes and push them to GitHub

Git iconGitHub icon

Summary

  • It is useful to make a package
    • it is fairly easy with devtools
    • it will help you work more reproducibly
  • Packages can be in one of 5 states:
    • source - what you write
    • bundled - source compressed to single file, submitted to CRAN
    • binary - distribution for users w/o devtools
    • installed - a binary that’s been decompressed
    • in-memory - installed package that has been loaded

Summary continued

  • A minimal package comprises
    • a folder which is a package and a RProj
    • DESCRIPTION, NAMESPACE, .Rbuildignore .gitignore
    • R/ directory for functions
  • We add functions with usethis:use_r()
  • We use the package interactively with devtools::load_all()
  • We use devtools::check() to execute R CMD check
  • We add a license with usethis::use_mit_license()

References

Curley, James. 2016. “Engsoccerdata: English and European Soccer Results 1871-2016.” https://CRAN.R-project.org/package=engsoccerdata.
Wickham, Charlotte, and Hadley Wickham. 2021. Building Tidy Tools. rstudio::conf 2020. https://github.com/rstudio-conf-2020/build-tidy-tools.
Wickham, Hadley. 2011. “Testthat: Get Started with Testing” 3. https://journal.r-project.org/archive/2011-1/RJournal_2011-1_Wickham.pdf.
Wickham, Hadley, Jennifer Bryan, and Malcolm Barrett. 2022. “Usethis: Automate Package and Project Setup.” https://CRAN.R-project.org/package=usethis.
Wickham, Hadley, and Jenny Bryan. 2020. R Packages. The work-in-progress 2nd edition. Online. https://r-pkgs.org/index.html.
Wickham, Hadley, Jim Hester, Winston Chang, and Jennifer Bryan. 2021. “Devtools: Tools to Make Developing r Packages Easier.” https://CRAN.R-project.org/package=devtools.