A little announcement. A lot to explore.

Happy learning!

Explore lessons, including SAS & R programs and practice data.

Search lessons

Type at least 3 characters to see matching lessons.

Open SAS ↗Open R ↗
← SASnRLoad an R package (library)

Introduction

  • Installing a package puts its files on disk. It does not make them usable yet.
  • To actually call the functions in a package, we have to attach it to the current R session. This is called loading the package.
  • In SAS, most procedures (PROC MEANS, PROC FREQ, PROC SORT and so on) are already built in. We almost never think about loading anything. R is the opposite by default — the base install is small, and anything beyond it has to be loaded every session.
  • The closest SAS analogue is attaching a format catalog or an autocall macro library: the code exists on disk, but SAS cannot see it until we point a LIBNAME or FMTSEARCH option at it.
  • In R, the command that does this is library().
  • Key things to remember before running the code below:
    • Loading is per session. Every time we start a fresh R session we have to load again.
    • If the package is not installed, library() throws an error. In that case, install first (see lesson 0110) and then load.
    • Once loaded, we can call a function directly by name (for example filter()) without the package:: prefix.

Load an R package (library)