R packages live most commonly on CRAN or GitHub. To install packages that live on CRAN, you use the function install.packages() which comes by default with R. To install packages that live on GitHub you use the function install_github(), which comes not by default but with the packages devtools and remotes. remotes has less features than devtools but it is often enough. remotes lives on CRAN, so you can install it with:

install.packages("remotes")

R packages are like any other software: After you install some software you generally can’t use it until you “open” it. To use an R package you “open” it with library(package). Let’s open remotes:

library(remotes)

Now you can use the function install_github(). The description and examples of the help file ?install_github() show you what to do next: You need to feed install_github() with the repository address in the format username/repo. For example, this is what you should run if you want to install the package tidyverse from the GitHub organization (equivalent to username) “tidyverse”:

install_github("tidyverse/tidyverse")

There is a way to save a little typing. You can use install_github() without running library(remotes): This is how:

remotes::install_github("hadley/tidyverse")

The syntax package::function works for any package. For example, had you installed devtools, you could also install tidyverse with:

devtools::install_github("hadley/tidyverse")

And now you can “open” tidyverse and start using it. For example:

# Open
library(tidyverse)
# Use
tidyverse_update()

Or you can use the syntax you just learned:

tidyverse::tidyverse_update()

To learn what a package does you can run help(package = "package-you-want-to-know-about"). For example:

help(package = "tidyverse")

Further reading

Other blogs about packages