Now that we've installed R in RStudio and have a basic understanding of how they work together, we can get at what makes R so special, packages. So far, anything we've played around with an R uses the Base R system. Base R or everything included in R when you download it has rather basic functionality for statistics and plotting, but it can sometimes be limiting. To expand upon R's basic functionality, people have developed packages. A package is a collection of functions, data, and code conveniently provided in a nice complete format for you. At the time of writing, there are just over 14,300 packages available to download, each with their own specialized functions and code, all for some different purpose. R package is not to be confused with the library. These two terms are often conflated in colloquial speech about R. A library is the place where the package is located on your computer. To think of an analogy, a library is well, a library, and a package is a book within the library. The library is where the book/packages are located. Packages are what make R so unique. Not only does Base R have some great functionality, but these packages greatly expand its functionality. Perhaps, most special of all, each package is developed and published by the R community at large and deposited in repositories. A repository is a central location where many developed packages are located and available for download. There are three big repositories. They are the Comprehensive R Archive Network, or CRAN, which is R's main repository with over 12,100 packages available. There is also the Bioconductor repository, which is mainly for Bioinformatic focus packages. Finally, there is GitHub, a very popular, open source repository that is not R specific. So, you know where to find packages. But there are so many of them. How can you find a package that will do what you are trying to do in R? There are a few different avenues for exploring packages. First, CRAN groups all of its packages by their functionality/topic into 35 themes. It calls this its task view. This at least allows you to narrow the packages, you can look through to a topic relevant to your interests. Second, there is a great website. R documentation, which is a search engine for packages and functions from CRAN, Bioconductor, and GitHub, that is, the big three repositories. If you have a task in mind, this is a great way to search for specific packages to help you accomplish that task. It also has a Task View like CRAN that allows you to browse themes. More often, if you have a specific task in mind, Googling that task followed by R package is a great place to start. From there, looking at tutorials, vignettes, and forums for people already doing what you want to do is a great way to find relevant packages. Great. You found a package you want. How do you install it? If you are installing from the CRAN repository, use the Install Packages function with the name of the package you want to install in quotes between the parentheses. Note, you can use either single or double quotes. For example, if you want to install the package ggplot2, you would use install.packages("ggplot2"). Try doing so in your R Console. This command downloads the ggplot2 package from CRAN and installs it onto your computer. If you want to install multiple packages at once, you can do so by using a character vector with the names of the packages separated by commas as formatted here. If you want to use RStudio's Graphical Interface to install packages, go to the Tools menu, and the first option should be Install Packages. If installing from CRAN, selected is the repository and type the desired packages in the appropriate box. The Bioconductor repository uses their own method to install packages. First, to get the basic functions required to install through Bioconductor, use source("https://bioconductor.org/biocLite.R") This makes the main install function of Bioconductor biocLite available to you. Following this you call the package you want to install in quote between the parentheses of the biocLite command as seen here for the GenomicRanges package. Installing from GitHub is a more specific case that you probably won't run into too often. In the event you want to do this, you first must find the package you want on GitHub and take note of both the package name and the author of the package. The general workflow is installing the devtools package only if you don't already have devtools installed. If you've been following along with this lesson, you may have installed it when we were practicing installations using the R console, then you load the devtools package using the library function SO. More on with this command is doing in a few seconds. Finally, using the command install_github calling the authors GitHub username followed by the package name. Installing a package does not make its functions immediately available to you. First, you must load the package into R. To do so, use the library function. Think of this like any other software you install on your computer. Just because you've installed the program doesn't mean it's automatically running. You have to open the program. Same with R you've installed it but now you have to open it. For example, to open the ggplot2 package, you would use the library function and call it ggplot2. Note do not put the package name in quotes. Unlike when you are installing the packages, the library command does not accept package names in quotes. There is an order to loading packages. Some packages require other packages to be loaded first, aka dependencies. That package is manual/help pages. We'll help you out and finding that order if they are picky. If you want to load a package using the RStudio interface, in the lower right quadrant, there is a tab called packages that list set all of the packages in a brief description as well as the version number of all of the packages you have installed. To load a package, just click on the checkbox beside the package name. Once you've got a package, there are a few things you might need to know how to do. If you aren't sure if you've already installed the package or want to check with packages are installed, you can use either of the Install Packages or library commands with nothing between the parentheses to check. In RStudio, that package tab introduced earlier is another way to look at all of the packages you have installed. You can check what packages need an update with a call to the functional packages. This will identify all packages that have been updated since you install them/Last updated them. To update all packages, use update packages. If you only want to update a specific package, just use once again install packages. Within the RStudio interface still in that Packages tab, you can click Update which will list all of the packages that are not up-to-date. It gives you the option to update all of your packages or allows you to select specific packages. You will want to periodically checking on your packages and check if you've fallen out of date, be careful though. Sometimes an update can change the functionality of certain functions. So if you rerun some old code, the command may be changed or perhaps even outright gone and you will need to update your CO2. Sometimes you want to unload a package in the middle of a script. The package you have loaded may not play nicely with another package you want to use. To unload a given package, you can use the detach function. For example, you would type detach package:ggplot2 then unload equals true in the format shown. This would unload the ggplot2 package that we loaded earlier. Within the RStudio interface in the Packages tab, you can simply unload a package by unchecking the box beside the package name. If you no longer want to have a package installed, you can simply uninstall it using the function Removed.packages. For example, remove packages followed by ggplot2 try that. But then actually reinstalled the ggplot2 package. It's a super useful plotting package. Within RStudio in the Packages tab, clicking on the X at the end of a package's row will uninstall that package. Sometimes, when you are looking at a package that you might want to install, you will see that it requires a certain version of R to run. To know if you can use that package, you need to know what version of R you are running. One way to know your R version is to check when you first open R or RStudio. The first thing it outputs in the console tells you what version of R is currently running. If you didn't pay attention at the beginning, you can type version into the console and it will output information on the R version you're running. Another helpful command is session info. It will tell you what version of R you are running along with a listing of all of the packages you have loaded. The output of this command is a great detail to include when posting a question to forums. It tells potential helpers a lot of information about your OS, R, and the packages plus their version numbers that you are using. In all of this information about packages, we have not actually discussed how to use a package's functions. First, you need to know what functions are included within a package. To do this, you can look at the manner help pages included in all well-made packages. In the console, you can use the help function to access a package's help file. Try using the help function calling package equals ggplot2 and you will see all of the many functions that ggplot2 provides. Within the RStudio interface, you can access the help files through the Packages tab. Again, clicking on any package name should open up these associated help files in the Help tab found in that same quadrant beside the Packages tab. Clicking on any one of these help pages will take you to that functions help page that tells you what that function is for and how to use it. Once you know what function within a package you want to use, you simply call it in the console like any other function we've been using throughout this lesson. Once a package has been loaded, it is as if it were a part of the base R functionality. If you still have questions about what functions within a package are right for you or how to use them, many packages include vignettes. These are extended help files that include an overview of the package and its functions, but often they go the extra mile and include detailed examples of how to use the functions in plain words that you can follow along with to see how to use the package. To see the vignettes included in a package, you can use the browseVignettes function. For example, let's look at the vignettes included in ggplot2 using browseVignettes followed by ggplot2, you should see that there are two included vignettes. Extending ggplot2 and aesthetics specification. Exploring the aesthetic specifications vignette is a great example of how vignettes can be helpful clear instructions on how to use the included functions. In this lesson, we've explored our packages in depth. We examined what a package is is and how it differs from a library, what repositories are, and how to find a package relevant to your interests. We investigated all aspects of how packages work, how to install them from the various repositories, how to load them, how to check which packages are installed, and how to update, uninstall, and unload packages. We took a small detour and looked at how to check with version of R you have which is often an important detail to know when installing packages. Finally, we spent some time learning how to explore help files and vignettes which often give you a good idea of how to use a package and all of its functions.