R’s popularity is also largely due to the many fantastic packages available in the language! A package is a bundle of code that makes coding certain tasks easier. There are all sorts of packages for all sorts of purposes, ranging from visualizing and cleaning data, to ordering pizza or posting a tweet. In fact, most R-grammers (R programmers) use packages when they code. This is why you might hear them differentiate packages from “Base R.” Base R refers the R language by itself and all that it can do without importing any packages.
Base R is very powerful, but most of the time, you’ll want to import a package to make your life easier. You only need to run this command the first time you install a package, after that there is no need to run it:
install.packages('package-name')
To import a package you simply:
library(package-name)
You can look up documentation for different packages available in R at the CRAN (Comprehensive R Archive Network).
In this lesson, we coded in Base R but let’s practice importing one of the most popular R packages: dplyr. Dplyr is a package used to clean, process, and organize data which you will use as you learn about R.
Instructions
Currently, the code inside notebook.Rmd throws an error because it uses the dplyr
and readr
packages without importing them. Import the dplyr
and readr
packages by using the library()
function and then press run so that you can observe the packages do their magic!