 The series is part of the R Fund Learning Resource website. The website is sponsored by the Center for Data and Visualization Sciences, part of the Duke University Libraries. Today we're going to talk about library packages, why you would use them, what they are, or else we're going to talk about the tidyverse, and we're going to talk about other sources for library packages. First of all, why would you use packages? Packages extend the functionality of your base R programming kernel. So if you have a particular subject domain that you're an expert in, you probably want to use packages that other subject domain developers have developed to make that world easier to analyze. You may want to write a package of your own that makes your subject area easier to analyze. A good example of library packages is the tidyverse. The tidyverse, by their own definition, is an opinionated collection of packages. What do they say? An opinionated collection of packages with consistent web-based documentation and a supportive community. But there's an important stuff there. Opinionated means they have a sense that this is the best or easiest way to use R. I happen to think more than nine times out of ten, they're correct. But that's what they mean by opinionated. They have a sense that there's a right way to use R or an easier way to use R. Easier than base R. I think that's correct. The other thing that tidyverse is, is a meta package that loads eight helper packages. It actually, when you install tidyverse, it installs tens of packages. Maybe 40 takes about five minutes to install. But the meta package, when you load it, only loads eight. So let's talk about that. When you install packages, you install them only once. You only need to install it once. It's always there. The next time you open up RStudio, that package is available to you. But in order to use that package, you have to load that package with the library function and to do that at every session. So let's take a look at that and see what it looks like. Here in a blank RStudio at the base, if I wanted to install a package, I could go over here to package and click install. If I want to install the tidyverse, I can just start typing tidyverse. And click on this install button right here. It will choose a default place to put those libraries. And it chooses from CRAN or the comprehensive R Archive Network, which are a whole host, thousands of packages, which have been through some rigor to be blessed as good and well-written packages. Packages exist in lots of places, not just on CRAN. There's packages. A lot of packages exist on tidyverse. Sorry, on a lot of packages exist on GitHub. We'll talk about how to install those. Bioconductor, R OpenSci, Metacran, other places to get packages, but a whole bunch of them are on CRAN and they're easy to install this way. Now, again, if I clicked install, I could install that. It would take about five minutes because tidyverse is a big package. Like I said, it installs about 40, I don't know, tens of packages anyway. And I don't need to do it because I've already got it installed. So if I scroll down here, or if I start typing tidyverse, I can actually load this package just by clicking on this check mark. When I do that, you'll see the command over here in the console. So if I type load, that's the command to load a package, library followed by the package name. In the case of tidyverse, like I said, it's a meta package. It loads eight packages. What are those eight packages? Let's have a look. There's ggplot, for plotting, for visualization, ggstand for grammar or graphics. There's tibble, which is for displaying your rectangular grid data, your data frames. There's tidyr, which I use principally for transforming data, pivoting wider, pivoting longer. A lot of data likes to be long. It's a great utility package for that. There's reader. That's for importing data, mostly text data, CSV data. There's purr. That's for iterating over your data frame or iterating over your list. That's an advanced topic. But purr is really handy. It basically modernizes and or replaces sapply, lapply, mapply, things like that. There's the plier. That's for transforming your data. That's a handy set of five, at least five verbs that are easier to remember than some of the code in base r. There's stringer. That's for manipulating natural language, for finding patterns in languages, for using regular expressions or regex. And there's four cats. That's for managing or manipulating categorical data. The other thing that when I loaded that library, it told me is that there are some conflicts, right? And the other filter, the filter function of the, of the deployer library is masking the stats, the filter function in the stats library. I can still run the stats filter function. I just have to type out the full reference to it. So stats is the package name or library name. And then filter is the filter function within stats. Conversely, by just type filter, the default, and you saw it there, that default is going to be the plier. Okay. The other thing it tells me then, of course, is that the lag function in the plier is masking the lag function in stats. All right. So real quickly, I'm going to give a quick demonstration of how you might load a library in an R Markdown script. I might create a second level heading here and say load library packages and then say tidyverse is really great and opinionated. Now I can make that work hotlink by using my Markdown. Then I can insert a code chunk and type in my library code chunk. If I want this code to be available to my technical audience, I'm going to leave it as is, but I might turn off the warnings because I don't want it to necessarily spit back that it loaded whatever the console is telling me. So I can load more than one library. And now that I have these warnings turned off, the console won't say anything below here, but it may say something, right? No, it turns it off in both places. Console won't say anything right here. The other thing I might do if I have a technical audience, if I have a non-technical audience, is I might choose to change this to show output only. In other words, to not show the code because maybe my non-technical audience doesn't care what packages I'm loading. Remember, install a package once, load it every time.