How to : Install R Packages

A Beginner’s Guide

Anne Sophie Gill https://www.skemagloballab.io/gillAnneSophie.html (SKEMA Global Lab in AI)https://skemagloballab.io , Thierry Warin https://www.nuance-r.com/principalInvestigator.html (SKEMA Business School (Raleigh, NC))https://www.skemagloballab.io
03-05-2020

This blog post will help you understand the difference between a package and a library, as well as show you how to install a package in the SKEMA Quantum Studio (Warin 2019).

Packages

Packages are collections of R functions, data, and compiled code in a well-defined format. The directory where packages are stored is called the library. R comes with a standard set of packages. Others are available for download and installation. Once installed, they have to be loaded into the session to be used.

Adding Packages

You can expand the types of analyses you do be adding other packages. A complete list of contributed packages is available from CRAN.

CRAN is the official repository, it is a network of ftp and web servers maintained by the R community around the world. The R foundation coordinates it, and for a package to be published here, it needs to pass several tests that ensure the package is following CRAN policies.

What’s The Difference Between A Package And A Library ?

Speaking about the library() function, sometimes there is a confusion between a package and a library, and you can find people calling “libraries” to packages. Please don’t get confused: library() is the command used to load a package, and it refers to the place where the package is contained, usually a folder on your computer, while a package is the collection of functions bundled conveniently.

How to use R packages

Follow these steps

Download and install a package (you only need to do this once). In your console, copy paste the function install.packages(). Inside the (), write the name of the package you are using inside quotation marks "", like so


# install.packages("package")

To use the package, invoke the library() command to load it into the current session.


# library(package)


Watch this video for a concrete example on how to install a package


Our packages

SKEMA Quantum Studio (Warin 2019) has created two package for CRAN :

statcanR

spiR

They are both officially part of The Comprehensive R Archive Network since the beginning of 2020.


Conclusion

R Packages will save you time — you don’t need to think about the best way to organise a project, you can just follow a template. Organising code in a package makes your life easier because packages come with conventions. Standardised conventions lead to standardised tools — if you buy into R’s package conventions, you get many tools for free. It’s even possible to use packages to structure your data analyses. Hopefully, this blog post helped you understand a bit better what R packages are, why we use them and how to use them.


Sources


Follow SKEMA Global Lab in Augmented Intelligence

Warin, Thierry. 2019. “SKEMA Quantum Studio: A Technological Framework for Data Science in Higher Education.” https://doi.org/10.6084/m9.figshare.8204195.v2.

Citation

For attribution, please cite this work as

Gill & Warin (2020, March 5). Blog: How to : Install R Packages. Retrieved from https://blog.skemagloballab.io/posts/2020-03-05-whatisapackage/

BibTeX citation

@misc{gill2020how,
  author = {Gill, Anne Sophie and Warin, Thierry},
  title = {Blog: How to : Install R Packages},
  url = {https://blog.skemagloballab.io/posts/2020-03-05-whatisapackage/},
  year = {2020}
}