title | author | institute | date | output | classoption | ||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Developing an R package: a tutorial |
Ghislain Durif (https://gdurif.perso.math.cnrs.fr/) |
CNRS -- LBMC (Lyon, France) |
July 2022 |
|
aspectratio=169,12pt |
All contents are available under CC-BY-4.0 license.
\Large \centering
https://plmlab.math.cnrs.fr/gdurif/devRpkg \bigskip
https://github.com/gdurif/devRpkg
Many hyperlinks are directly embedded in the slide contents.
-
R (the latest version if possible\footnote{Keep your software up-to-date! If you need an older version of R for a specific project, use appropriate tools like containers, it should be an exception not a habit.},
4.2.1
since 2022-06-23)\bigskip -
You can use the R command line combined with any text editor, but we recommend to use an R-oriented IDE\footnote{\href{https://en.wikipedia.org/wiki/Integrated_development_environment}{Integrated Development Environment}} like Rstudio or RKWard \bigskip
-
All content presented here have been tested on a Linux environment but should work on any OS \bigskip
-
Note for Windows users: you can update R from within R with the
installr
package and you will need to install Rtools to enable all R development functionality \bigskip
-
See the script
install_requirements.R
to install the packages that will be used in the tutorial \bigskip \bigskip -
To (re)generate the slides, see the scripts^[or the attached
Makefile
if you are confortable with usingmake
].setup.R
to install the requirement,.build.R
to build thepdf
slides
- Official R documentation: Writing R Extensions \bigskip
- Karl Broman tutorial: R package primer (web version and sources) \bigskip
- Hadley Wickham and Jenny Bryan book: R packages (web version and sources) \bigskip
- Hilary Parker tutorial on writing R packages \bigskip
- Rstudio cheatsheets on package development and Rstudio IDE
-
a library containing a set of R functions (and possibly more) implementing functionality not available in default R functions\footnote{or reimplementing existing functionality in a different way} \bigskip
-
a standardized way to distribute R codes (for other users) \bigskip
- the
CRAN
(Comprehensive R Archive Network): official repository for R packages
install.packages("devtools")
-
bioconductor
: bioinformatics-oriented package repository \bigskip -
any git forge: github, gitlab, etc. \bigskip
-
on your colleagues' computers\footnote{if they develop in R} \bigskip
-
The best way to write and distribute R code with documentation, examples, tests, etc. \bigskip
-
A good practice\footnote{even for codes you don't plan to publish/distribute} when coding in R: \medskip
- your project is structured (code, data, doc), easier to use and re-use \smallskip
- documentation is essential (including for your future self) \smallskip
- your code is standardized, you can check it and test your functions \smallskip
- easy management of dependencies
- etc.
A wide variety of tools to help you:
-
Rstudio IDE built-in development features \bigskip
-
R base built-in tools: build (
R CMD build
), check (R CMD check
) \bigskip -
Some packages to develop packages (non-exhaustive):\medskip
usethis
: to automate package and project setupdevtools
: complete collection of development toolsroxygen2
: to document your code and generate help pagestestthat
: to implement automatic tests of your functionsremotes
: to install package from anywhere (integrated indevtools
)rmarkdown
andknitr
: to create detailed documentation materials and notebooks (code showcase)
\footnotesize
- Getting started
- R package structure
- Workflow
- Getting started
- Digression: Good practice for software development and programming (not just in R)
- Test your functions
- Sharing (your code) is caring
- Advanced documentation
- Non R code
- Control your R environment