Use Github Actions to …
Published:
If you are an R package developer, and you host your code on GitHub, there a few tasks that you will need to do repeatedly to ensure user experience is pleasant and that your code is stable.
- Ensure your package can be installed, without issues, on several different operating systems
- Maintain and update a website
Fortunately, there are easy to use tools to make this process pretty painless. They involve the idea of continuous integration. You make changes to some of your code and the changes are integrated automatically. This process is continuous through time.
The automation part of this process is through GitHub actions
. These are scripts that reside in your GitHub repository that define a workflow to be executed on GitHub servers and are triggered to run based on a variety of events.
While these GitHub actions can be quite complex, and have their own syntax, there are templates available for the R user to achieve certain tasks, effortlessly, using the package usethis
. For example
R-CMD checks
You may be developing an R package on a windows machine but want to ensure that all users (Windows, Mac, and Linux) will be able to install your package without issues. You can not test this yourself, since you don’t have a Mac or Linux box, and you don’t want to keep bugging a friend who does. So instead you set up a GitHub action to do this:
usethis::use_github_action("check-standard")
The command above will create a standard template for you and add it to the appropriate spot in your repo. That’s it!
Every time you make a commit to the main or development branch (best practices suggest you should have both!), or make a pull request (you can customize these “triggers”) the GitHub action workflow will start by booting up several virtual machines in parallel to check if your code can be successfully installed on multiple platforms. This is equivalent of a devtools::check
on multiple platforms all at once!
Build a pkgdown website
Along the same lines you can get GitHub Actions to continuously update your pkgdown
website with every pull request made to the main branch.
usethis::use_github_action("pkgdown")
will set up everything for you to get you up and running. Now all you need to do write the documentation! See the great manual on R packages for details on how to document your code
Other uses
You can also create custom GitHub Actions to do just about anything. For example:
- Pull data from an API on a defined schedule/cron job
- Automatically build and push docker images to a repository like DockerHub.
- Send yourself an email with a custom report
- Plus many more