Skip to content

2.1: Design

Ian Lyttle edited this page Jun 11, 2022 · 1 revision

This is a way for Ian to keep track of the states for day 2 of the workshop.

For Ian's purposes a state refers to:

  • files in the R directory
  • files in the tests/testthat directory
  • the Imports and Suggests entries in the DESCRIPTION file

These files, 👆, can be summoned using btt22::btt_reset(), but hopefully no-one will need to do so.

A state also refers to a set of files that will be templated into the R and tests/testthat directories; you can use btt22::btt_get() to get these files.

Both of these functions take a single argument, state. You can get the available states using btt22::btt_state().

2.1.1 Start

This is the initial state for the functions day.

We have two files in R:

Files:

  • R/ussie_package.R
  • R/matches.R
  • tests/testthat/test-matches.R

In DESCRIPTION:

Imports: 
    dplyr,
    tibble
Suggests:
    engsoccerdata,
    conflicted,
    knitr,
    rmarkdown,
    roxygen2,
    testthat (>= 3.0.0)

Tasks

  1. usethis::use_package("rlang")
  2. usethis::use_import_from("rlang", ".data")
  3. add .data pronoun, as needed, to uss_get_matches() in matches.R

Result

R CMD CHECK will be happy.

2.1.2 Set up functions

We have some files to be templated in:

  • R/columns.R
  • R/get-matches.R
  • tests/testthat/test-get-matches.R

Tasks

  1. usethis::use_package("engsoccerdata") (import rather than suggest)
  2. run devtools::check(), we get a NOTE
  3. btt22::btt_get("2.1.2"), see that devtools::check() is almost happy (🤔: using R 4.2.0, I don't get a note)
  4. usethis::use_package("utils") (maybe this is not necessary, see 👆)
  5. see that devtools::check() is happy (maybe this is not necessary, see 👆)
  6. go through new code, why we have to use these tricks
  7. exercise:
  • use function from columns.R in test-matches.R
  • write up uss_countries() and uss_get_matches() in vignette

Result

  • we have two new functions: uss_countries() and uss_get_matches().
  • R CMD CHECK will be happy.
Clone this wiki locally