The Tidyverse
This lesson is called The Tidyverse, part of the R in 3 Months (Fall 2022) course. This lesson is called The Tidyverse, part of the R in 3 Months (Fall 2022) course.
Transcript
Click on the transcript to go to that point in the video. Please note that transcripts are auto generated and may contain minor inaccuracies.
Your Turn
First, download the course project using the following code:
install.packages("usethis")
library(usethis)
use_course("http://bit.ly/fundamentals-of-r-course")
Then, do the following:
Open the data-wrangling-and-analysis-exercises.Rmd file
Load packages
Import NHANES data and use the
clean_names
function on it.
Learn More
To see the most downloaded R packages, check out the trends page of the RDocumentation website. Note that because tidyverse is a collection of packages, you will see it show up among the most downloaded packages as well as individual packages that are part of it (e.g. ggplot2).
To learn about the clean_names function, check out the janitor package docs. Note that there are many options for how you can format your variable names. I like snake_case myself so use that (it's also the default).
To see a great set of slides on Tidyverse basics, check out these from Alison Hill.
Have any questions? Put them below and we will help you out!
Course Content
142 Lessons
You need to be signed-in to comment on this post. Login.
Hatem Kotb • March 20, 2021
I've followed the same code but I'm getting an error message as shown below. Any idea why? Thanks! :)
-- Column specification -------------------------------------------------------------------------------------- cols( .default = col_character(), ID = col_double(), Age = col_double(), Weight = col_double(), Height = col_double(), BMI = col_double(), DaysPhysHlthBad = col_double(), DaysMentHlthBad = col_double(), SleepHrsNight = col_double(), PhysActiveDays = col_double(), TVHrsDay = col_logical() ) i Use
spec()
for the full column specifications.4859 parsing failures. row col expected actual file 5001 TVHrsDay 1/0/T/F/TRUE/FALSE 2_hr './data/nhanes.csv' 5002 TVHrsDay 1/0/T/F/TRUE/FALSE More_4_hr './data/nhanes.csv' 5003 TVHrsDay 1/0/T/F/TRUE/FALSE 4_hr './data/nhanes.csv' 5004 TVHrsDay 1/0/T/F/TRUE/FALSE 4_hr './data/nhanes.csv' 5005 TVHrsDay 1/0/T/F/TRUE/FALSE 1_hr './data/nhanes.csv' .... ........ .................. ......... ................... See problems(...) for more details
Hatem Kotb • March 20, 2021
Seems like it's a warning message rather, not an error message. Would still like to understand more how to fix/navigate it. Thanks! :)
Oindrila Bhattacharyya • March 25, 2021
While trying to download the janitor package, I am getting an error message "Error in library(janitor) : there is no package called ‘janitor’ " Can you please tell me what to do now?
Vuk Sekicki • March 27, 2021
Just a word of advice from beginner. I just watched: https://vimeo.com/320973807 02:47. this is essential slide and explanation for me. I could not compute which of the forthcoming functions work on rows and which on columns.
Erin Guthrie • March 31, 2021
For a number of attempts, I kept getting this error: Error: package or namespace load failed for ‘tidyverse’ in loadNamespace(j library(tidyverse) Error: package or namespace load failed for ‘tidyverse’ in loadNamespace(j <- i[[1L]], c(lib.loc, .libPaths()), versionCheck = vI[[j]]): there is no package called ‘cellranger’
After some googling, I just installed "cellranger" separately and that seemed to resolve the issue. Is this common or do I have something set up incorrectly?
Naomi Nichols • April 13, 2021
Should I be worried about all of this red text? : Warning: 4859 parsing failures. row col expected actual file 5001 TVHrsDay 1/0/T/F/TRUE/FALSE 2_hr 'data/nhanes.csv' 5002 TVHrsDay 1/0/T/F/TRUE/FALSE More_4_hr 'data/nhanes.csv' 5003 TVHrsDay 1/0/T/F/TRUE/FALSE 4_hr 'data/nhanes.csv' 5004 TVHrsDay 1/0/T/F/TRUE/FALSE 4_hr 'data/nhanes.csv' 5005 TVHrsDay 1/0/T/F/TRUE/FALSE 1_hr 'data/nhanes.csv' .... ........ .................. ......... ................. See problems(...) for more details.
Juan Clavijo • September 27, 2021
Hello! I'm getting this error message: Error in library(janitor) : there is no package called ‘janitor’
Not sure what to do about it to be able to use clean names.
Thanks! Juan
David Keyes Founder • September 27, 2021
For anyone who needs it, you can use this URL in place of the bit.ly one to access the course materials as a zip file: https://codeload.github.com/rfortherestofus/fundamentals/zip/refs/heads/master
David Keyes Founder • September 28, 2021
You can definitely do that, though I think there are some caveats to consider. I recorded a video to explain my thinking and show you how I'd do things. The code I show in the video is here.
Israel Johnson • October 4, 2021
After executing the 2nd code chunk instructions the following message was generated: Column specification Delimiter: "," chr (13): SurveyYr, Gender, AgeDecade, Race1, Education, MaritalStatus, HHIncome, HomeOwn, Work, HealthGen, ... dbl (9): ID, Age, Weight, Height, BMI, DaysPhysHlthBad, DaysMentHlthBad, SleepHrsNight, PhysActiveDays
i Use
spec()
to retrieve the full column specification for this data. i Specify the column types or setshow_col_types = FALSE
to quiet this message.Should I be worried about these last two rows?
Dana Loll • March 31, 2022
Hi there! Getting this code when loading janitor. The following objects are masked from ‘package:stats’:
I know that this may be ok for our purposes now but I love chi square & fisher's tests! Any way to keep them? Or are they done in another package?
Carolyn Ford • April 2, 2022
Whenever I try these "usethis" commands, I always get this feedback:
Error in curl::curl_download(url = url, destfile = destfile, quiet = quiet, : Recv failure: Connection was reset
Carolyn Ford • April 2, 2022
Never mind - ended up using the codeload from github.
Tatiana Bustos • July 27, 2022
Hi there
I keep getting errors about the janitor package. I dont see it listed in the tab for packages either. Any other suggestions?
> library(janitor) Error in library(janitor) : there is no package called ‘janitor’ > library (janitor) Error in library(janitor) : there is no package called ‘janitor’ > install.packages (janitor) Error in install.packages : object 'janitor' not found > install.packages(janitor) Error in install.packages : object 'janitor' not found
Kirstin O'Dell • September 30, 2022
I keep getting this error message: Error in read.csv("data/nhanes.csv") %>% clean_names() : could not find function "%>%"
I have the following libraries loaded with the code below. What am I missing?
Ellen Wilson • January 24, 2023
This all worked for me when I did the sample exercise. I am now trying to work with some SurveyMonkey data I have from an actual survey I am working on, and having some difficulty. First of all, the variable names are insanely long (all the words of every question). I don't know if there is a better way to deal with it, but I was thinking that I would just rename all of them (e.g., rename " x2_what_grade_are_you_in" to "grade"). This is tedious, but maybe necessary? Making it more tedious, though, is the fact that even though I ran clean_names, the autocomplete function doesn't seem to be working. Any thoughts on what the problem could be? Typing out all the words in every one of these very long variable names would be a huge pain... Thanks for any guidance!
Chelsea Ruder • March 24, 2023
Where do I find the data-wrangling-and-analysis-exercises.Rmd file ??
Amanda Braley • March 25, 2023
Hmmm I have an error getting started: > library(usethis) Warning: package ‘usethis’ was built under R version 4.2.3Error: package or namespace load failed for ‘usethis’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]): namespace ‘rlang’ 1.0.6 is already loaded, but >= 1.1.0 is required
Andrew Paquin • March 26, 2023
When I try to do the last step, I get this message" Error in read_csv("data/nhanes.csv") %>% clean_names() : could not find function "%>%" Not sure what I'm doing wrong. I'm having a lot of trouble with RStudio tonight.
Zain Asaf • April 1, 2023
Hi David, Previously I was able to get half-way through the select exercise assignments. However, notwwhen I run the code from the start, run the clean_name function- I use the following codeL nhanes% clean_names() But I get the following error message: Use
spec()
to retrieve the full column specification for this data. i Specify the column types or setshow_col_types = FALSE
to quiet this message. >Use
spec()
to retrieve the full column specification for this data. i Specify the column types or setshow_col_types = FALSE
to quiet this message.Abdulkadir Lokhandvala • April 7, 2023
Hi David/Charlie - I am continuously getting below error and not able to progress in my course materials. Warning: package ‘tidyverse’ was built under R version 4.2.3Error: package or namespace load failed for ‘tidyverse’: .onAttach failed in attachNamespace() for 'tidyverse', details: call: NULL error: package or namespace load failed for ‘ggplot2’ in loadNamespace(i, c(lib.loc, .libPaths()), versionCheck = vI[[i]]): namespace ‘rlang’ 1.0.6 is already loaded, but >= 1.1.0 is required
Innocent Ouko • June 3, 2023
Hello, I have been trying to practice lesson but on a single file and this is the error message I got after trying to knit the entire document, which, as a result, makes no output:
Error: The name of the input file cannot contain the special shell characters: [ ()|:&;#?*'] (attempted to copy to a version without those characters 'Fundamentals-of-R.Rmd' however that file already exists) Execution halted