Who attended Part 1?
Who has started creating their own package?
What is your favourite R package?
There are benefits (beyond sharing) to bundling your code as an R package:
You can also bundle your research project as an R package!
We need your help!
Your mission, should you choose to accept, is to help create a communidefaultnaming-things/):
Ideas:
Check if the name is already in use
Most of the process can be achieved with the {devtools} and {usethis} packages
Important
Windows users will have to install Rtools
This creates the following files:
<packagename>
├── .Rbuildignore
├── .gitignore
├── DESCRIPTION
├── NAMESPACE # DO NOT EDIT
├── R
└── <packagename>.Rproj
Main part of the R package
Tasks:
Useful for participants:
(Code-along) Extract information on upcoming session
Whenever you create or modify a function, it needs to be (re-)loaded
This can be done with the load_all()
function from {devtools}
This will make sure packagename is installed on a user’s system when your package is installed.
If you install the package now, the functions will be missing
They need to be exported
Add yourself as a contributor to the DESCRIPTION under Authors@R
Authors@R: c(
person("Example", "Person1", email = "ex1@example.com", role = c("aut", "cre"),
comment = c(ORCID = "0000-0001-2345-6789")),
person("Example", "Person2", role = "aut",
comment = c(ORCID = "0000-0002-2345-6789"))
)
abbreviations:
Note
The DESCRIPTION file format is that of a version of a ‘Debian Control File’ (https://www.debian.org/doc/debian-policy/ch-controlfields.html)
Package states:
Package locations
Official: CRAN install.packages("packagename")
Development: GitHub (mostly) devtools::install_github("username/packagename")
Naming
Functions
devtools::load_all()
#' @export
Documentation
devtools::document()
We created a package!
Download the binary from the R console:
Or clone the git repo to get the source:
A good way to catch issues is the {testthat} package
which you can apply to your package with… you guessed it, {usethis}
it creates
tests
├── testthat
└── testthat.R # DO NOT EDIT
Add a testing script
Then add a test to run:
Test passed 🎊
This is just a generic example; ideally you should include statements about functions in the package
Run tests when you modify functions
Testing is also part of check()
Check that your package meets criteria for a functional R package
This function will tell you about issues with your package
Here is a typical workflow when working on package development:
document()
(if you’ve made any changes that impact help files or NAMESPACE)load_all()
test()
(or test_active_file()
)check()
22nd March - Topic: TBD
26th April - Topic: APIs (featuring Sofia Gil Clavel)
24th May - Topic: TBD
delft-rcafe.github.io/home/
rcafe-lib@tudelft.nl
delft-rcafe