Bergen R-Ladies Workshop

Making and Publishing Your First R Package

Tags: R tutorial

In August I had the absolute pleasure of not only visiting Bergen, but also giving a workshop to the local R-Ladies group on how to make a simple R package with {usethis}. Together, we live-coded a package from scratch called fjoRds, pushed it to Github, and made a {pkgdown} website to accompany it. The slides and also full presentation (it was recorded!) are below.

R hexagon patch for the fjoRds package developed in this tutorial. This simple package allows you to check if a given fjord is in Norway or not.

The slides

Click on the slides below to navigate with your arrow keys. Or, if you prefer, check out the slides full screen in a separate window.

The code that makes these slides is on Github here, if you want to see how they were made.

In summary

  • We create a new R project that will house our package
  • We write a (very simple) function that checks if a fjord is in Norway:
# "Sognefjord is a nice Norwegian fjord!"

fjord_finder("Sechelt Inlet")
# "Sechelt Inlet - I see you're in Canada, eh!"

# "Illulissat? Never heard of em."
  • We learn how to add references to outside (imported) packages and how to bundle a dataset with our package
  • And finally, we push the project to Github and create a {pkgdown} website for our package!

The presentation

You’ll have to excuse the few technical hiccups - I only had one screen to work with so the screensharing wasn’t optimal.


I can’t take full credit for this presentation - this tutorial is modified from a phenomenal tutorial I originally found on Matt Dray’s Rostrum blog (which helped me make my own first package!). However, the code in that tutorial was already a bit outdated by this point, so I updated it with the latest function usage.

In addition to Matt Dray’s resource suggestions, I would also add Patricio R Estévez-Soto’s post, Your first R package: A tutorial, to the list.