15:00
~30 min
Important
Var names can contain letters, numbers, underscores and periods only. They must start with a letter.
Brackets | ( , ) |
Add | + |
Subtract | - |
Multiply | * |
Divide | / |
Exponent | ^ or ** |
Square root | sqrt |
True | TRUE |
False | FALSE |
And | & |
Or | | |
Not | ! |
Test equal numbers | all.equal |
A package is a container of functions and data sets.
A library is a folder in your computer that store packages. They can be of three type:
{renv}
package… we will see that)Important
Install a package stores its R executable code in a library.
Attach a package let you able to use its functions and dataset within the current R session.
You need to install a package you want to use once only.
All the time you (re)start an R session, you need to library(<pkg>)
again.
Important
Functions and data are identified by their names (which cannot be duplicate within the same package).
Attaching a package to an R session, it means to make its function and data names available for you to call/use. I.e., you have expanded the language (within the session)!
The tidyverse is an opinionated collection of R packages designed for data science. All packages share an underlying design philosophy, grammar, and data structures.
{ggplot2}
: create data visualizations using the Grammar of Graphics.{dplyr}
: a set of verbs to solve data manipulation challenges.{tidyr}
: a set of functions that help you get to tidy data.{readr}
: a fast and friendly way to read rectangular data{purrr}
: a consistent tools suite for functional programming.{tibble}
: a modern re-imagining of the data frame.{stringr}
: a set of functions to work with strings as easy as possible.{forcats}
: a tool suite that solves common problems with factors.{lubridate}
: a tool suite to work with dates and date-times.Your turn
Connect to the Day-1 project in RStudio cloud (https://bit.ly/ubep-rws-rstudio)
Create a new script and write the following code in it. Save the script. (install the mentioned package first)
Run the script and check the result in the console.
Open the help page of the tibble
package and read it; focus more on the structure of the help page instead of the content.
Groups
library(tidyverse)
db_tbl <- tibble(
age = c(70, 85, 69),
height = c(1.5, 1.72, 1.81),
at_risk = c(TRUE, FALSE, TRUE),
gender = factor(
c("male", "female", "female"),
levels = c("female", "male", "other")
)
)
db_tbl
15:00
YOU: Connect to our pad(https://bit.ly/ubep-rws-pad-3ed) and write there questions & doubts (and if I am too slow or too fast)
ME: Connect to the Day-1 project in RStudio cloud (https://bit.ly/ubep-rws-rstudio): script 05-packages.R
To create the current lesson we explored, use, and adapt contents from the following resources:
The slides are made using Posit’s Quarto open-source scientific and technical publishing system powered in R by Yihui Xie’s kintr.
This work by Corrado Lanera, Ileana Baldi, and Dario Gregori is licensed under CC BY 4.0
UBEP’s R training for supervisors