Requirements

Develop an R package within an hour

It is much easier to create, manage and co-develop an R package when you incorporate it into a distributed version control system like git. The extension to a software development hosting service like GitHub is then a natural one. Although there are other procedures and DevOps systems and hosting services that may lend itself for package development, we outline the workflow with git and GitHub.

That said, you can follow the first part of tutorial without the use of git or GitHub. We will assume that you have RStudio available (installed or online).

Assumed prior knowledge

Using RStudio
RStudio is an R user’s best friend. The IDE provides an enhanced interface for coding in R, with built-in support for markdown languages and R package development. If you’re not familiar with R or RStudio, or need a refresher, please follow the tutorial in our crash course before continuing.

Using Git
Git is a free and open source version control system for text files. It can handle extensive change logging for you, no matter the size of the project. Git is fast and efficient, but its effectiveness depends also on the frequency you instruct it to log your project’s changes.

You can see Git as a blank canvas that starts at a certain point in time. Every time you (or others) instruct Git to log any changes that have been made, Git adds the changes that are made to this canvas. We call the changes to the canvas commits. With every commit an extensive log is created that includes at least the following information:

  • the changes made
  • who made the changes
  • metadata
  • a small piece of text that describe the changes made

The difference between two commits - or the changes between them - are called diffs.

If you’d like to know much more about Git, this online book is a very good resource. If you’d like to practice with the command line interface use this webpage for a quick course. This book covers pretty much everything you need to marry Git and R.

Using GitHub
GitHub is the social and user interface to Git that allows you to work in repositories. These repositories can be seen as project folders in which you publish your work, but you can also use them as test sites for development, testing, etcetera. There is a distinction between private repositories (only for you and those you grant access) and public repositories (visible for everyone).

Your public repositories can be viewed and forked by everyone. Forking is when other people create a copy of your repository on their own account. This allows them to work on a repository without affecting the master. You can also do this yourself, but then the process is called branching instead of forking. If you create a copy of a repository that is offline, the process is called cloning.

GitHub’s ability to branch, fork and clone is very useful as it allows other people and yourself to experiment on (the code in) a repository before any definitive changes are merged with the master. If you’re working in a forked repository, you can submit a pull request to the repository collaborators to accept (or reject) any suggested changes.

System requirements

Installation of R and RStudio or login online on Posit Cloud.

1. Check R version (you will need version 4.1 or higher)

R.version$version.string
[1] "R version 4.5.0 (2025-04-11)"

2. Check installation of R packages

You will need the R packages devtools and dplyr. You can verify whether all packages are installed correctly by running:

all(c("devtools", "dplyr", "roxygen2", "usethis", "testthat") %in% rownames(installed.packages()))
[1] TRUE

If not yet installed, run:

install.packages(c("devtools", "dplyr", "roxygen2", "usethis", "testthat"))

1. Go to https://posit.cloud/ and click on “Sign Up” in the top-right corner.

2. Select “Cloud free” by clicking “Learn more” and sign up.

3. Go to https://docs.posit.co/cloud/get_started/ and follow the instructions up to and including “Create a Project”.

4. In the ‘Build’ tab, click ‘Configure build tools’ and make sure ‘Project build tools’ is set to “Package”.

5. Install the necessary R packages

install.packages(c(
  "devtools",
  "dplyr",
  "roxygen2",
  "testthat",
  "knitr",
  "usethis",
  "here"
))

6. Set the working directory to the project root.

setwd(here::here())

Installing git, and the benefits of GitHub for R package development.

I suggest you install Git by downloading and installing GitHub Desktop. GitHub’s desktop application is a nice GUI and, naturally, integrates well into the repository workflow on GitHub.

When installed, you can go to GitHub Desktop > Install Command Line Tool

After a reboot, all should be set.

Download and install Git for Windows, Then download and install GitHub Desktop. GitHub’s desktop application is a nice GUI and, naturally, integrates well into the repository workflow on GitHub.

After a reboot, all should be set.

GitHub for R package development
GitHub is the social and user interface to Git that allows you to work in repositories. These repositories can be seen as project folders in which you publish your work, but you can also use them as test sites for development, testing, etcetera. There is a distinction between private repositories (only for you and those you grant access) and public repositories (visible for everyone).

Your public repositories can be viewed and forked by everyone. Forking is when other people create a copy of your repository on their own account. This allows them to work on a repository without affecting the master. You can also do this yourself, but then the process is called branching instead of forking. If you create a copy of a repository that is offline, the process is called cloning.

GitHub’s ability to branch, fork and clone is very useful as it allows other people and yourself to experiment on (the code in) a repository before any definitive changes are merged with the master. If you’re working in a forked repository, you can submit a pull request to the repository collaborators to accept (or reject) any suggested changes.

For now, this may be confusing, but I hope you recognize the benefits GitHub can have on the process of development and bug-fixing. For example, the most up-to-date version of the mice package in R can be directly installed from the mice repository with the following code devtools::install_github(repo = "amices/mice").

You can see that this process requires package devtools that expands the R functionality with essential development tools. Loading packages in R directly from their respective GitHub repositories, allows you to obtain the latest - often improved and less buggy - iteration of that software even before it is published on CRAN.

Opening an account
Go to GitHub and sign up. You may qualify for a free PRO subscription through GitHub’s education benefits.



Copyright Hanne Oberman, 2025 - CC BY-NC-SA 4.0
Materials developed by Amices team - Methodology & Statistics - Utrecht University