-
Notifications
You must be signed in to change notification settings - Fork 1
R Package Development Workflow
Dimi edited this page Jul 6, 2021
·
1 revision
- write a test (optional / only when trying to do test-driven development)
- run the tests to see it fail
devtools::test()or CTRL+SHIFT+T (Win+Linux) or CMD+SHIFT+T (Mac)
- write (a draft of) a function in
R/, document it with roxygen comments (R6 specifics here or by looking at R6 based packages) - Load the function and "test" in the R terminal
devtools::load_all()or CTRL+SHIFT+L (Win+Linux) or CMD+SHIFT+L (Mac)
- IF you already know how to do this, write unit test(s) for your function (see here) - if you don't know this yet, ask the others :)
- Run all tests to see whether everything is still working (see 2.)
Repeat 1-6
- Check your style and update your code accordingly
styler::style_pkg(style = styler::tidyverse_style, indent_by = 4) - check the package: this will not only run unit tests but will also check other aspects of the package, like whether documentation is complete, the DESCRIPTION file is ok, ...
devtools::check()or
rcmdcheck::rcmdcheck()- Update documentation: If you add or export new functions / classes or add / remove arguments, you should update the documentation
devtools::document()or CTRL+SHIFT+D (Win+Linux) or CMD+SHIFT+D (Mac)
| Description | Win + Linux | Mac |
|---|---|---|
| Load All (devtools) | CTRL+SHIFT+L | CMD+SHIFT+L |
| Test Package (Desktop) | CTRL+SHIFT+T | CMD+SHIFT+T |
| Document Package | CMD+SHIFT+D | CMD+SHIFT+D |
| Check Package | CMD+SHIFT+E | CMD+SHIFT+E |
| (Build and Reload) | CMD+SHIFT+B | CMD+SHIFT+B |
Note on VSCode: If you develop in VSCode, you can add shortcuts by opening your keybindings.json ("Open Keyboard Shortcuts (JSON)") and adding blocks like this:
{
"description": "run all tests",
"key": "cmd+shift+t",
"command": "r.runCommand",
"when": "editorLangId == r && editorTextFocus || terminalFocus",
"args": "devtools::test()"
}
- R code goes into
R - tests go into
tests/testthat -
mancontains the documentation for the package (see below) - if we want to have internal or external data, this blog post is a great resource
- the NAMESPACE chapter is quite informative to read
- add it to the "Imports" in the DESCRIPTION file -> this ensures that the package is installed when the user installs the package
- in your function, use the
::notation to refer to the function, e.g.crul::HttpClient - according to
R packagesthis is the preferred way- unless we use a function a lot, then we could also use the
@importFromroxygen tag, cf. here
- unless we use a function a lot, then we could also use the
Project Workflow
Kobo API
Learning