Skip to content

Latest commit

 

History

History
120 lines (78 loc) · 5.67 KB

index.md

File metadata and controls

120 lines (78 loc) · 5.67 KB
title author institute date output classoption
Developing an R package: a tutorial
CNRS -- LBMC (Lyon, France)
July 2022
binb::metropolis
includes
in_header
.latex_style.sty
aspectratio=169,12pt

License

All contents are available under CC-BY-4.0 license.

Training materials

\Large \centering

https://plmlab.math.cnrs.fr/gdurif/devRpkg \bigskip

https://github.com/gdurif/devRpkg

Note for the reader

Many hyperlinks are directly embedded in the slide contents.

Requirements (1)

  • 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

Requirements (2)

  • 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 using make] .setup.R to install the requirement, .build.R to build the pdf slides

References

What is an R package?

  • 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

Where can I find R packages?

  • 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

Why R packages?

  • 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.

How to write an R package?

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 setup
    • devtools: complete collection of development tools
    • roxygen2: to document your code and generate help pages
    • testthat: to implement automatic tests of your functions
    • remotes: to install package from anywhere (integrated in devtools)
    • rmarkdown and knitr: to create detailed documentation materials and notebooks (code showcase)

Outline

\footnotesize

  1. The essentials to write your package (.md and .pdf)
  • Getting started
  • R package structure
  • Workflow
  1. Going further with your R package development (.md and .pdf)
  • 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