Bergen R-Ladies Workshop
Making and Publishing Your First R Package
2022-08-17
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.
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:
fjord_finder("Sognefjord")
# "Sognefjord is a nice Norwegian fjord!"
fjord_finder("Sechelt Inlet")
# "Sechelt Inlet - I see you're in Canada, eh!"
fjord_finder("Illulissat")
# "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.
Resources
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.