From the course: Learning the R Tidyverse
Installing, loading, and working with the tidyverse packages - R Tutorial
From the course: Learning the R Tidyverse
Installing, loading, and working with the tidyverse packages
- [Instructor] The tidyverse ecosystem is designed from the ground up for simplicity and consistency, including how you get the packages into your machine and load them into your R sessions. Let's look at how we would install the tidyverse in R by moving over to our project 01_01b. I have inside of the Files tab a script called ggplot2.R, and what I'm trying to do is replicate your situation. So you may have been running code already and you want to install the tidyverse. So I've got this code, I'm going to run it. To pretend I was working on this before, I wanted to install the tidyverse. So to install the tidyverse, I would come to the console and I would type install.packages tidyverse. And I get this warning about updating loaded packages. This is because I've already loaded ggplot2. And when we do install.packages, that's going to go and get the most up-to-date version of ggplot2. That's an issue. The best practice is to always restart your R session before installing new packages. Let me show you how to do that. So we'll click on Cancel. We'll go to Session in the menu bar and we'll select Restart R. We now have a completely fresh R session. Let's go to our console and type install.packages tidyverse. And when I hit Enter, it's going to go away to cron install all the packages that I don't have on my machine. And when you run it, it will install all the packages that you don't have. So I'll hit Enter. And I already have many of these packages installed, so it doesn't take that long for all of the remaining tidyverse packages to be installed. So the installation is finished when you get to this point here. So you have the prompt and the flashing cursor. It might take longer on your machine. Great. Now we've got these packages installed, let's talk about how we would use them. The tidyverse packages are split into two very distinct groups. There's the core tidyverse and there're specialized tidyverse packages. The core tidyverse packages are loaded all at the same time with library tidyverse, whereas the specialized packages need to be loaded individually. As we progress through the course, we'll get to grips with all of the core tidyverse packages and a fair few of the specialized ones. Don't worry if you are unfamiliar with most of these packages for the time being. So let's go over to RStudio and load our packages. In fact, let's change line one from library ggplot2 to library tidyverse. And when I run this, it's going to load the tidyverse and the tidyverse package, it's quite noisy. It likes to tell you which packages have been loaded. And so it says that it's attaching the core tidyverse packages and you can see those nine core tidyverse packages. Now, how about for other packages? readxl was one of those. readxl is a great package for reading in an Excel file. To load that package, we would need to explicitly load it. So I would type library readxl, and run that code. And that's loaded the package. And now, in my autocompletion, if I type read_excel, we can see this function read_excel from the readxl package. Now that we understand the tidyverse's split into core and specialized packages and how to load those packages, it's important to know what does the core tidyverse give us? It's easiest to split the core packages into groups of packages. The first group, tibble, dplyr, and tidyr equip us with the high-level tools we need to wrangle, manipulate, and transform rectangular data. The second group, stringr, lubridate, and forcats are low-level tools that we can use alongside the first group of packages to clean, sanitize strings and dates, as well as manipulating the order of factor variables. The remaining packages kind of live on their own. readr gives us everything we need to read flat files, including .CSV files. purrr provides a toolkit for functional programming, which admittedly, many tidyverse users never need to use. And the final package, ggplot2, is a fully-featured package for data visualization and that is why the core tidyverse is so powerful.
Contents
-
-
-
What is the tidyverse?2m 22s
-
Installing, loading, and working with the tidyverse packages5m 1s
-
(Locked)
Introducing data.frame and tibbles8m 34s
-
What are %>% and |> for in the tidyverse3m 46s
-
(Locked)
Using the %>% pipe in your code5m
-
(Locked)
Using the |> pipe in your code6m 18s
-
(Locked)
Datasets built into the tidyverse packages3m 15s
-
(Locked)
Using the select() function to obtain columns from data4m 23s
-
(Locked)
Using the filter() function to filter data by conditions6m 10s
-
(Locked)
Using the mutate() function to modify and add columns4m
-
(Locked)
Challenge: Rewrite this code to use the pipe of your choice2m 38s
-
(Locked)
Solution: Rewrite this code to use the pipe of your choice3m 19s
-
-
-
-
-
-
-