Development Workflow

See 3.1 HTML document in „R Markdown: The Definitive Guide” by Yihui Xie, J. J. Allaire, Garrett Grolemund.

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  fig.path = "man/figures/devworkflow-",
  out.width = "100%"
)

`%>%` <- purrr::`%>%`
library(devtools)
library(fs)
fs::dir_info(
    all = TRUE,
    recurse = TRUE,
    regexp = "^(.git|.Rproj.user|.+\\.(html|md))/.+",
    invert = TRUE) %>% 
  dplyr::select(path, type)

2.6 Write the first function

use_r("make_arrays")

Put the following definition in R/make_arrays.R an save it.

make_arrays <- function(m = 5, n = 5) {
  array(NA, c(m, n))
}
load_all() # shift + ctrl + L  or  shift + command

make_arrays(2, 4)
#>      [,1] [,2] [,3] [,4]
#> [1,]   NA   NA   NA   NA
#> [2,]   NA   NA   NA   NA
check()

2.10 Edit DESCRIPTION

use_mit_license("Wlodek Bzyl")
# ✓ Setting active project to '/Users/wbzyl/RPKGS/GUMED/rraysplot'
# ✓ Writing 'LICENSE.md'
# ✓ Adding '^LICENSE\\.md$' to '.Rbuildignore'
# ✓ Writing 'LICENSE'
check()

2.12 document()

Would not it be nice to get help on make_arrays(), just like we do with other R functions?

This requires that your package have a special R documentation file, man/make_arrays.Rd.

document()
# Updating rraysplot documentation
# Loading rraysplot
# Writing NAMESPACE
# Writing make_arrays.Rd
check()

2.14 install()

Since we have a minimum viable(?) product now, let’s install the foofactors package into your library via install():

install()
# * installing to library ‘/Users/wbzyl/Library/R/4.0/library’
library(rraysplot)
make_arrays(4, 3)

2.15 use_testthat()

use_testthat()
# ✓ Adding 'testthat' to Suggests field in DESCRIPTION
# ✓ Creating 'tests/testthat/'
# ✓ Writing 'tests/testthat.R'
# ● Call `use_test()` to initialize a basic test file and open it for editing.
use_test("make_arrays")
# ✓ Writing 'tests/testthat/test-make_arrays.R'
# ● Modify 'tests/testthat/test-make_arrays.R'
library(testthat)
load_all()
test() # cmd + shift + T

2.18 use_readme_rmd()

Now that your package is on GitHub, the README.md file matters.

It is the package’s home page and welcome mat, at least until you decide to give it a website with pkgdown, add a vignette, or submit it to CRAN.

use_readme_rmd()

✓ Setting active project to '/Users/wbzyl/RPKGS/GUMED/rraysplot'
✓ Writing 'README.Rmd'
✓ Adding '^README\\.Rmd$' to '.Rbuildignore'
● Modify 'README.Rmd'
✓ Writing '.git/hooks/pre-commit'

You'll still need to render README.Rmd regularly, to keep README.md up-to-date.

devtools::build_readme()

is handy for this.

2.16 use_package()

We’re going to add another function to package. We’ll borrow some smarts from the another package, for example the function expand_grid from the tidyr and %>% from the purrr package.

First, declare your general intent to use some functions from the tidyr namespace with use_package():

use_package("tidyr")
use_package("purrr")
use_package("tibble")

Next, optionally(?), we add these lines to the source R file (R/plot_array2d.R):

#' @importFrom purrr %>% map map_dbl
#' @importFrom tidyr expand_grid
#' @importFrom tibble tibble


ventri2020/rraysplot documentation built on Jan. 1, 2021, 12:38 p.m.