A Beginner’s Guide
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 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.
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.
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.
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
To use the package, invoke the library() command to load it into the current session.
Watch this video for a concrete example on how to install a package
SKEMA Quantum Studio (Warin 2019) has created two package for CRAN :
They are both officially part of The Comprehensive R Archive Network since the beginning of 2020.
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.
Warin, Thierry. 2019. “SKEMA Quantum Studio: A Technological Framework for Data Science in Higher Education.” https://doi.org/10.6084/m9.figshare.8204195.v2.