Automatic tools for improving packages

Maƫlle Salmon (@ma_salmon)

RUG Barcelona, 13th of June 2017

Introduction

Who am I? (1/2)

  • Data manager/statistician for CHAI project at ISGlobal.

  • PhD in statistics.

  • R user, developper, addict.

  • R-Ladies BCN co-organizer.

  • Co-editor at rOpenSci onboarding (more on that later!)

Who am I? (2/2): Mowgli’s sister!

What does improving the package mean?

  • Coding style (against errors, and for future readers&contributors)

  • Tests (such good safeguards!)

  • Structure (follow the rules)

  • Documentation (think of the users, including you in 3 months!)

  • Not mentioned today: features, performance

Functions for improving packages!

Automatic tools?

  • Automatic suggestions of improvements

  • Not automatic corrections… Animo!

Today’s talk

For each tool,

Questions any time chic@s!

R CMD Check

R CMD Check, what’s that?

  • Necessary before any CRAN submission, useful anyway

  • Package structure (bye bye, left-over files), missing documentation, dependencies.

  • Runs tests, checks examples and vignettes.

  • ERROR/WARNING/NOTE

R CMD Check live

Not time for it but…

  • Continuous integration is great!

https://juliasilge.com/blog/beginners-guide-to-travis/

lintr, Static Code Analysis for R

What is Jim Hester’s lintr?

Let’s use lintr!

Bonus tip, lintr unit test

  • the test
if (requireNamespace("lintr", quietly = TRUE)) {
  context("lints")
  test_that("Package Style", {
    lintr::expect_lint_free()
  })
}
  • .lintr at the root if non-default linters
with_defaults(camel_case_linter = NULL, # you prefer camel case 
              snake_case_linter, # so flag snake case
              line_length_linter(120)) # you love long lines

goodpractice, Advice on R Package Building by Gabor Csardi

goodpractice presentation

  • https://github.com/MangoTheCat/goodpractice

  • actually uses some lintr linters.

  • tunable but I like the defaults.

  • ā€œAdvice includes functions and syntax to avoid, package structure, code complexity, code formatting, etc.ā€

goodpractice and fakepackage

devtools::spell_check()

devtools::spell_check()

  • Function written by Jeroen Ooms.

  • Let’s try it!

  • Also good to know, devtools::release() when submitting a package to CRAN.

pkgdown, Generate static html documentation for an R package

pkgdown

pkgdown for fakepackage

  • pkgdown::build_website() after correcting my name.

  • Change settings of the Github repo.

  • Add URL in repo and advertise it!

pkgdown on fakepackage: customization

  • Create a file at the root of the repo called _pkgdown.yml

  • Styles, see https://bootswatch.com/

  • Group functions & vignettes. Use pkgdown::template_blabla as starting point.

Example https://github.com/dirkschumacher/ompr/blob/master/_pkgdown.yml

Conclusion

Tools we’ve seen

  • R CMD check

  • lintr

  • devtools::spell_check()

  • goodpractice::gp()

  • pkgdown::build_site()

Tools we haven’t seen

Further resources

Small tip before even creating your package

Package name check via available. https://github.com/ropenscilabs/available

available::available("dplyr")
available::available("chicken")

Have your code&docs read by humans

Where to find me

  • Github: maelle

  • Twitter: ma_salmon

And you can also talk to me now!

Thanks for coming and listening!