Spring clean your R packages
Did you know we maintain a number of public R packages on our GitHub page. Some of these packages were developed way back in 2019. Since then, the standards in R package development have changed a little and we thought it was time to have a little spring clean of our packages.
In this blog post, we’ll be using functions from the {usethis} package to spruce up some of our old packages. We’ve chosen five quick improvements which you should be able to implement in 15 minutes or less. Grab your duster and come along.
Rename master to main
We wrote a whole blog post on why it’s a good idea to move the default branch name from master
to the more neutral name, main
. Luckily, renaming a single repository is straightforward and this one command will basically do everything for you.
usethis::git_default_branch_rename()
Tidy your description file
Your DESCRIPTION
file is argubly the most important file in your R package as it defines the purpose of your code and contains important metadata. Take a minute to check that the key fields are still correct, in particular the contact email address, description and any URLs.
You can then run
usethis::use_tidy_description()
which will put the fields in a standard order and alphabetise the dependencies. It’s looking tidier already. 😌
Migrate to GitHub Actions
TravisCI used to be the most popular tool for continuous integration in the #RStats community. In recent years, many R package developers have moved away from Travis CI to GitHub Actions. Dean Attali wrote a detailed guide explaining the migration process in full. However, for most simple packages, all we need to do is delete the existing travis.yml
file, and then run
usethis::use_github_action("check-standard")
to set up the standard GitHub action. This action will run R CMD check
using R-latest on Linux, Mac, and Windows. This is a good baseline if you plan on submitting your package to CRAN. It will also add a lovely badge to your README.md
that will show users that your package is passing the check.
If your R package has tests, you might also want to run
usethis::use_github_action("code-coverage")
which will calculate your test coverage and report to codecov.io.
Create a hex sticker
We all know that the most important part of any R package is the hex sticker. If you don’t already have one, you easily can create one in R with {hexSticker}.
You can choose any image or plot to position on your sticker. You can then customise it by changing the colours, fonts and adding a url.
sticker(subplot = "hoover.png", s_x=1, s_y=.75,
h_fill = "#4898a8", h_color = "#516e7a",
package = "springClean", p_size=20,
url = "jumpingrivers.com", u_color = "#FFFFFF", u_size = 6,
filename = "sticker.png")
You can add the hex sticker as a logo to your package with another helpful {usethis} function.
usethis::use_logo("sticker.png")
Contributing and Code of Conduct
One of the great things about R package developement is that it’s a team effort. If you want people to contribute to the development of your R packages, you need to tell them how to contribute. It’s also a good idea to add a code of conduct, to set an example of how we should work together.
At Jumping Rivers, we follow the standard contributing and CoC guides that the tidyverse developers use. Again, {usethis} provides functions that make adding these files to your package really easy.
usethis::use_tidy_contributing()
usethis::use_coc(contact = "hello@jumpingrivers.com")
Get involved
That’s it for our quick spring clean. We always welcome new contributors to our R packages. If you have any issues or want to make a PR head over to our GitHub page.
And if we’ve inspired you to dust off your old R packages and give them some love, let us know on Twitter/X.