-
+
data |
gapminder |
-
+
aesthetic mapping |
x: gdpPercap , y: lifeExp |
-
+
geometric object |
points |
-
+
scale |
x: log10, y: linear |
-
+
statistical transform |
none |
-
+
coordinate system |
rectangular |
-
+
facetting |
none |
@@ -198,6 +189,16 @@ Example: your first ggplot2 plot
ylab("Life Expectancy")
+
+
Test Your Understanding
+
+- True or False: You can re-specify global aesthetics by adding an
aes()
layer to a ggplot object.
+- True or False: With ggplot2, we can specify the data in a geom layer, in addition to the initial
ggplot()
layer.
+- True or False: Because the
dplyr::group_by()
function and ggplot2’s group
aesthetic both split a tibble into groups, we can use either one when making a plot.
+- True or False: In principle, mapping
continent
to letters (a, b, c, …) is an aesthetic mapping.
+
+
+
Your turn: learning to use ggplot2
We think the best way to learn the basics of ggplot2 is to work through Worksheet A3.
@@ -240,7 +241,7 @@
Class 2: FEV Case Study
Example:
-```r
+``` r
ggplot(gapminder, aes(lifeExp)) +
geom_histogram(bins = 50)
```
@@ -263,7 +264,7 @@
Class 2: FEV Case Study
Example:
-```r
+``` r
ggplot(gapminder, aes(lifeExp)) +
geom_density()
```
@@ -282,7 +283,7 @@
Class 2: FEV Case Study
Example:
-```r
+``` r
ggplot(gapminder, aes(continent, lifeExp)) +
geom_jitter()
```
@@ -301,7 +302,7 @@
Class 2: FEV Case Study
Example:
-```r
+``` r
ggplot(gapminder, aes(continent, lifeExp)) +
geom_boxplot()
```
@@ -323,7 +324,7 @@
Class 2: FEV Case Study
Example:
-```r
+``` r
ggplot(gapminder, aes(lifeExp, continent)) +
ggridges::geom_density_ridges()
```
@@ -351,7 +352,7 @@
Class 2: FEV Case Study
Example: number of 4-, 6-, and 8- cylinder cars in the `mtcars` dataset:
-```r
+``` r
ggplot(mtcars, aes(cyl)) +
geom_bar()
```
@@ -370,7 +371,7 @@
Class 2: FEV Case Study
Although not required, the `group` aesthetic will come in handy here. This aesthetic produces a plot independently for each group, and overlays the results.
-```r
+``` r
tsibble::as_tsibble(co2) %>%
rename(yearmonth = index,
conc = value) %>%
@@ -381,6 +382,12 @@
Class 2: FEV Case Study
ylab("CO2 Concentration")
```
+```
+## Registered S3 method overwritten by 'tsibble':
+## method from
+## as_tibble.grouped_df dplyr
+```
+
diff --git a/content/notes/notes-a09.Rmd b/content/notes/notes-a09.Rmd
index efa969da..e3da2a06 100644
--- a/content/notes/notes-a09.Rmd
+++ b/content/notes/notes-a09.Rmd
@@ -37,13 +37,6 @@ Other resources, in addition to the notes below:
- If you're eager to learn more about models in general, [An Introduction to Statistical Learning](https://www-bcf.usc.edu/~gareth/ISL/) is an approachable read (the book is freely available online)
- [Mike Marin's R playlist on YouTube](https://www.youtube.com/playlist?list=PLqzoL9-eJTNBlVXxWvJkq0dtVut2sICUW) helps you use R to obtain statistical results.
-## Test Your Understanding
-
-1. TRUE or FALSE: the output of `glance` on the above returns only 1 row because there is only 1 explanatory variable in the model.
-2. TRUE or FALSE: the output of `broom::tidy()` package is more "tidy" than `coef(summary())` because the output is a `tibble`
-3. TRUE or FALSE: We need to use a modelling function, such as `lm`, before we can graph a fitted line with `geom_smooth`.
-4. TRUE or FALSE: If I wanted to find the amount that `lifeExp` changes per `year`, then I need to use `broom::tidy()`
-
# Model-fitting in R
Data wrangling and plotting can get you pretty far when it comes to drawing insight from your data. But, sometimes you need to go further. For example:
@@ -313,6 +306,15 @@ ggplot(gapminder_Zimbabwe, aes(year,lifeExp)) +
5. `geom_smooth()` - used to add geom_layer that shows a fitted line to the data. `method` and `formula` arguments can be used to customize model.
+## Test Your Understanding
+
+1. TRUE or FALSE: the output of `glance` on the above returns only 1 row because there is only 1 explanatory variable in the model.
+2. TRUE or FALSE: the output of `broom::tidy()` package is more "tidy" than `coef(summary())` because the output is a `tibble`
+3. TRUE or FALSE: We need to use a modelling function, such as `lm`, before we can graph a fitted line with `geom_smooth`.
+4. TRUE or FALSE: If I wanted to find the amount that `lifeExp` changes per `year`, then I need to use `broom::tidy()`
+
+---
+
## Your turn: learning to fit models in R
We think the best way to learn the basics from here is to work through the last part of Worksheet A4.
diff --git a/content/notes/notes-a09.html b/content/notes/notes-a09.html
index 7640f9a8..c681a8b6 100644
--- a/content/notes/notes-a09.html
+++ b/content/notes/notes-a09.html
@@ -31,15 +31,6 @@
Resources
Mike Marin’s R playlist on YouTube helps you use R to obtain statistical results.
-
-
Test Your Understanding
-
-- TRUE or FALSE: the output of
glance
on the above returns only 1 row because there is only 1 explanatory variable in the model.
-- TRUE or FALSE: the output of
broom::tidy()
package is more “tidy” than coef(summary())
because the output is a tibble
-- TRUE or FALSE: We need to use a modelling function, such as
lm
, before we can graph a fitted line with geom_smooth
.
-- TRUE or FALSE: If I wanted to find the amount that
lifeExp
changes per year
, then I need to use broom::tidy()
-
-
Model-fitting in R
Data wrangling and plotting can get you pretty far when it comes to drawing insight from your data. But, sometimes you need to go further. For example:
@@ -267,6 +258,16 @@
Summary
geom_smooth()
- used to add geom_layer that shows a fitted line to the data. method
and formula
arguments can be used to customize model.
+
+
Test Your Understanding
+
+- TRUE or FALSE: the output of
glance
on the above returns only 1 row because there is only 1 explanatory variable in the model.
+- TRUE or FALSE: the output of
broom::tidy()
package is more “tidy” than coef(summary())
because the output is a tibble
+- TRUE or FALSE: We need to use a modelling function, such as
lm
, before we can graph a fitted line with geom_smooth
.
+- TRUE or FALSE: If I wanted to find the amount that
lifeExp
changes per year
, then I need to use broom::tidy()
+
+
+
Your turn: learning to fit models in R
We think the best way to learn the basics from here is to work through the last part of Worksheet A4.
diff --git a/content/notes/notes-a10.Rmd b/content/notes/notes-a10.Rmd
index 8713db2d..d72a0986 100644
--- a/content/notes/notes-a10.Rmd
+++ b/content/notes/notes-a10.Rmd
@@ -33,32 +33,6 @@ Other resources, in addition to the notes below:
- The [R4DS](https://r4ds.had.co.nz/dates-and-times.html) chapter on Dates and Times
- The `tsibble` [vignette](https://cran.rstudio.com/web/packages/tsibble/vignettes/intro-tsibble.html) to learn more about embedding a time series within a tibble.
-## Test Your Understanding
-
-1. The output of the following code is equivalent to a factor with the letters "a" to "f".
-
-``` r
-(abc <- factor(letters[1:3]))
-#> [1] a b c
-#> Levels: a b c
-(def <- factor(letters[4:6]))
-#> [1] d e f
-#> Levels: d e f
-c(abc, def)
-```
-
-2. The output of the following code is a date object.
-
-```r
-library(lubridate)
-
-date <- ymd("2020-10-13")
-
-dt <- ymd_hms("2020-10-13 09:30:00")
-
-c(date, dt)
-```
-
## Factors
> "There is no other object that creates as much trouble as factors." - Patrick Burns, "The R Inferno".
@@ -106,6 +80,33 @@ Often you will need to work with dates and times in your data. For example, we c
Dates and times seem simple, but they are actually one of the most complicated things you will encounter in data analysis.
+## Test Your Understanding
+
+1. The output of the following code is equivalent to a factor with the letters "a" to "f".
+
+``` r
+(abc <- factor(letters[1:3]))
+#> [1] a b c
+#> Levels: a b c
+(def <- factor(letters[4:6]))
+#> [1] d e f
+#> Levels: d e f
+c(abc, def)
+```
+
+2. The output of the following code is a date object.
+
+```r
+library(lubridate)
+
+date <- ymd("2020-10-13")
+
+dt <- ymd_hms("2020-10-13 09:30:00")
+
+c(date, dt)
+```
+
+
--------------
## Your turn: Making a date variable
diff --git a/content/notes/notes-a10.html b/content/notes/notes-a10.html
index b81ef03e..f8f82885 100644
--- a/content/notes/notes-a10.html
+++ b/content/notes/notes-a10.html
@@ -30,29 +30,6 @@
Resources
-
-
Test Your Understanding
-
-- The output of the following code is equivalent to a factor with the letters “a” to “f”.
-
-
(abc <- factor(letters[1:3]))
-#> [1] a b c
-#> Levels: a b c
-(def <- factor(letters[4:6]))
-#> [1] d e f
-#> Levels: d e f
-c(abc, def)
-
-- The output of the following code is a date object.
-
-
library(lubridate)
-
-date <- ymd("2020-10-13")
-
-dt <- ymd_hms("2020-10-13 09:30:00")
-
-c(date, dt)
-
Factors
@@ -73,7 +50,8 @@ Factors
Under the hood, R stores a factor with (say) 3 levels as a numeric vector containing integers between 1 and 3, paired with a character vector of length 3 that identifies the mapping between the numbers 1, 2, and 3 and the levels.
This is not immediately obvious, because R will print factors using the character string levels rather than the numbers that it stores:
penguins %>% slice_sample(n=10) %>% pull(species)
-## [1] Adelie Adelie Gentoo Gentoo Gentoo Gentoo Adelie Gentoo Adelie Adelie
+## [1] Gentoo Adelie Adelie Gentoo Gentoo Adelie Adelie
+## [8] Chinstrap Adelie Adelie
## Levels: Adelie Chinstrap Gentoo
This dual nature of factors creates a whole slew of hidden traps and headaches, especially for new useRs!
Nevertheless, factors are important and worth the pain. Many functions throughout the R landscape expect categorical variables to be coded as factors. For example, when making plots in either ggplot2
or in base R, we need factors in order to map categorical variables to aesthetic elements like colour.
@@ -101,9 +79,32 @@ Second part
Third part: Dates and/or Times
Often you will need to work with dates and times in your data. For example, we could have had a variable in the FEV data set that contains the date of each patient visit.
Dates and times seem simple, but they are actually one of the most complicated things you will encounter in data analysis.
-
+
+
Test Your Understanding
+
+- The output of the following code is equivalent to a factor with the letters “a” to “f”.
+
+
(abc <- factor(letters[1:3]))
+#> [1] a b c
+#> Levels: a b c
+(def <- factor(letters[4:6]))
+#> [1] d e f
+#> Levels: d e f
+c(abc, def)
+
+- The output of the following code is a date object.
+
+
library(lubridate)
+
+date <- ymd("2020-10-13")
+
+dt <- ymd_hms("2020-10-13 09:30:00")
+
+c(date, dt)
+
+
Your turn: Making a date variable
diff --git a/content/notes/notes-a12.Rmd b/content/notes/notes-a12.Rmd
index bd245647..dd7c6d1c 100644
--- a/content/notes/notes-a12.Rmd
+++ b/content/notes/notes-a12.Rmd
@@ -21,12 +21,6 @@ Tutorial:
- The ["Writing and Reading files"](https://stat545.com/import-export.html) chapter of stat545.com.
-## Test your Understanding
-
-1. True or False: if you want to be deliberate about where `here::here()` points to on your computer, you need to ensure you have an .Rproj file.
-2. True or False: Suppose you have an .Rproj file in the same folder as your R script. Running `here::here()` from that R script will always point to that folder.
-
-
## Formats
Here are a few formats that you might want to read and write data to:
@@ -52,6 +46,13 @@ Want to read and write to an Excel file? The `readxl` package in the tidyverse i
For the very niche option of R binary: `read_rds()` and `write_rds()`.
+## Test your Understanding
+
+1. True or False: if you want to be deliberate about where `here::here()` points to on your computer, you need to ensure you have an .Rproj file.
+2. True or False: Suppose you have an .Rproj file in the same folder as your R script. Running `here::here()` from that R script will always point to that folder.
+
+---
+
## Your turn: try it out!
Open RStudio. Go to Session => Set Working Directory => Choose Directory and then pick a folder you would like to read and write data into. Then, run the following piece of code:
diff --git a/content/notes/notes-a12.html b/content/notes/notes-a12.html
index 77fc9259..a3b4f894 100644
--- a/content/notes/notes-a12.html
+++ b/content/notes/notes-a12.html
@@ -23,13 +23,6 @@ Resources
- The “Writing and Reading files” chapter of stat545.com.
-
-
Test your Understanding
-
-- True or False: if you want to be deliberate about where
here::here()
points to on your computer, you need to ensure you have an .Rproj file.
-- True or False: Suppose you have an .Rproj file in the same folder as your R script. Running
here::here()
from that R script will always point to that folder.
-
-
+
+
Test your Understanding
+
+- True or False: if you want to be deliberate about where
here::here()
points to on your computer, you need to ensure you have an .Rproj file.
+- True or False: Suppose you have an .Rproj file in the same folder as your R script. Running
here::here()
from that R script will always point to that folder.
+
+
+
Your turn: try it out!
Open RStudio. Go to Session => Set Working Directory => Choose Directory and then pick a folder you would like to read and write data into. Then, run the following piece of code:
diff --git a/content/notes/notes-b02.Rmd b/content/notes/notes-b02.Rmd
index 3495ba0c..ca9fb672 100644
--- a/content/notes/notes-b02.Rmd
+++ b/content/notes/notes-b02.Rmd
@@ -41,16 +41,6 @@ Written material:
- [Package development cheat sheet](https://rawgit.com/rstudio/cheatsheets/master/package-development.pdf)
- To learn more about using S3 object oriented functions in your package, see ["Advanced R" Chapter 13: S3](https://adv-r.hadley.nz/s3.html).
-## Test Your Understanding
-
-It might help to browse a completed package directory to answer these questions, like the [powers package](https://github.com/vincenzocoia/powers).
-
-1. True or False: The mandatory files in an R package are a DESCRIPTION file, a NAMESPACE file, and functions in the R/ directory -- everything else is just helpful.
-2. So far we've been using devtools functions in the console (instead of saved in a script). True or False: if you're making a bigger R package, you should start putting those devtools functions in one or more R scripts.
-3. True or False: Add any package name to the `Imports` field in the DESCRIPTION file, and we can now use functions from that package using `::`.
-4. True or False: We can't *both* add exports to the NAMESPACE file manually and by using `devtools::document()`.
-
-
## Why R Packages
Why make an R package? As mentioned in the "functions" topic, your analysis will probably benefit from homemade functions: making functions forces you to think about your analysis in terms of its key computational parts, and makes for robust and readable code. Here are a few benefits that result by bundling these functions into an R package:
@@ -99,4 +89,13 @@ Release your package:
- Make a NEWS.md file with `use_news_md()` and add the main development notes.
- Choose a version number; put in description file, and tag a release on GitHub.
- - You should also prepare your package for the next version -- I suggest doing this on a new branch.
\ No newline at end of file
+ - You should also prepare your package for the next version -- I suggest doing this on a new branch.
+
+## Test Your Understanding
+
+It might help to browse a completed package directory to answer these questions, like the [powers package](https://github.com/vincenzocoia/powers).
+
+1. True or False: The mandatory files in an R package are a DESCRIPTION file, a NAMESPACE file, and functions in the R/ directory -- everything else is just helpful.
+2. So far we've been using devtools functions in the console (instead of saved in a script). True or False: if you're making a bigger R package, you should start putting those devtools functions in one or more R scripts.
+3. True or False: Add any package name to the `Imports` field in the DESCRIPTION file, and we can now use functions from that package using `::`.
+4. True or False: We can't *both* add exports to the NAMESPACE file manually and by using `devtools::document()`.
diff --git a/content/notes/notes-b02.html b/content/notes/notes-b02.html
index 148b87ab..a769dd23 100644
--- a/content/notes/notes-b02.html
+++ b/content/notes/notes-b02.html
@@ -43,16 +43,6 @@
Resources
To learn more about using S3 object oriented functions in your package, see “Advanced R” Chapter 13: S3.
-
-
Test Your Understanding
-
It might help to browse a completed package directory to answer these questions, like the powers package.
-
-- True or False: The mandatory files in an R package are a DESCRIPTION file, a NAMESPACE file, and functions in the R/ directory – everything else is just helpful.
-- So far we’ve been using devtools functions in the console (instead of saved in a script). True or False: if you’re making a bigger R package, you should start putting those devtools functions in one or more R scripts.
-- True or False: Add any package name to the
Imports
field in the DESCRIPTION file, and we can now use functions from that package using ::
.
-- True or False: We can’t both add exports to the NAMESPACE file manually and by using
devtools::document()
.
-
-
Why R Packages
Why make an R package? As mentioned in the “functions” topic, your analysis will probably benefit from homemade functions: making functions forces you to think about your analysis in terms of its key computational parts, and makes for robust and readable code. Here are a few benefits that result by bundling these functions into an R package:
@@ -112,3 +102,13 @@
Agenda
+
+
Test Your Understanding
+
It might help to browse a completed package directory to answer these questions, like the powers package.
+
+- True or False: The mandatory files in an R package are a DESCRIPTION file, a NAMESPACE file, and functions in the R/ directory – everything else is just helpful.
+- So far we’ve been using devtools functions in the console (instead of saved in a script). True or False: if you’re making a bigger R package, you should start putting those devtools functions in one or more R scripts.
+- True or False: Add any package name to the
Imports
field in the DESCRIPTION file, and we can now use functions from that package using ::
.
+- True or False: We can’t both add exports to the NAMESPACE file manually and by using
devtools::document()
.
+
+
diff --git a/content/notes/notes-b03.Rmd b/content/notes/notes-b03.Rmd
index cae68bc1..afeb1b9f 100644
--- a/content/notes/notes-b03.Rmd
+++ b/content/notes/notes-b03.Rmd
@@ -34,19 +34,6 @@ No video lecture for this optional topic. Written material:
-
-## Test Your Understanding
-
-Use these questions to check your understanding of the material.
-
-1. True or False: You've opened Terminal, and are now about to run `Rscript` for a second time. Because you haven't restarted the Terminal, the code will continue to build in the same session as before.
-2. You have information in `script1.R` that you'd like to pass to `scipt2.R`. True or false: the best way to pass the info to `script2.R` is by saving the final workspace from `script1.R` in an `.RData` or `.rds` file, and loading that it into `script2.R`.
-3. True or False: It's almost always better to write an `.Rmd` file over an `.R` file, because you're able to interlace markdown.
-4. True or false: `make`ing a *phony* target will always run its rules, whereas `make`ing a target *file* will only run its rules if the output needs updating.
-5. True or false: If a dependency file is not present on your computer, you can still call `make` error-free if the dependency is the target of another rule. This is true even if the dependency never gets made.
-6. True or false: The rules to `make` a target file will be run if either the target file or the dependencies are modified.
-7. True or false: Dependencies in `make` are accessed "lazily", so that if the dependencies are never actually used when executing a rule, they don't actually have any impact on the Makefile.
-
## Why Automation
It often makes sense to break up a task (e.g. "analyze data and turn it into publication ready figures and tables") into smaller chunks, e.g. "data cleaning" vs "summarizing and plotting" vs "model fitting". This leads to a *pipeline*: a system where the code for some tasks (e.g. summarizing and plotting) depend on the output of others (e.g. data cleaning).
@@ -180,6 +167,20 @@ Once we get there, we'll work through the activity in [stat545.com Chapter 36](h
+
+## Test Your Understanding
+
+Use these questions to check your understanding of the material.
+
+1. True or False: You've opened Terminal, and are now about to run `Rscript` for a second time. Because you haven't restarted the Terminal, the code will continue to build in the same session as before.
+2. You have information in `script1.R` that you'd like to pass to `scipt2.R`. True or false: the best way to pass the info to `script2.R` is by saving the final workspace from `script1.R` in an `.RData` or `.rds` file, and loading that it into `script2.R`.
+3. True or False: It's almost always better to write an `.Rmd` file over an `.R` file, because you're able to interlace markdown.
+4. True or false: `make`ing a *phony* target will always run its rules, whereas `make`ing a target *file* will only run its rules if the output needs updating.
+5. True or false: If a dependency file is not present on your computer, you can still call `make` error-free if the dependency is the target of another rule. This is true even if the dependency never gets made.
+6. True or false: The rules to `make` a target file will be run if either the target file or the dependencies are modified.
+7. True or false: Dependencies in `make` are accessed "lazily", so that if the dependencies are never actually used when executing a rule, they don't actually have any impact on the Makefile.
+
+
#### Attribution
Written by Vincenzo Coia, with inspiration from Tiffany Timbers for the explanation of Makefiles, as well as the make activity from Shaun Jackman and Jenny Bryan created for this course prior to 2017.
\ No newline at end of file
diff --git a/content/notes/notes-b03.html b/content/notes/notes-b03.html
index 07dab04b..bb5b784e 100644
--- a/content/notes/notes-b03.html
+++ b/content/notes/notes-b03.html
@@ -37,19 +37,6 @@ Resources
-
-
Test Your Understanding
-
Use these questions to check your understanding of the material.
-
-- True or False: You’ve opened Terminal, and are now about to run
Rscript
for a second time. Because you haven’t restarted the Terminal, the code will continue to build in the same session as before.
-- You have information in
script1.R
that you’d like to pass to scipt2.R
. True or false: the best way to pass the info to script2.R
is by saving the final workspace from script1.R
in an .RData
or .rds
file, and loading that it into script2.R
.
-- True or False: It’s almost always better to write an
.Rmd
file over an .R
file, because you’re able to interlace markdown.
-- True or false:
make
ing a phony target will always run its rules, whereas make
ing a target file will only run its rules if the output needs updating.
-- True or false: If a dependency file is not present on your computer, you can still call
make
error-free if the dependency is the target of another rule. This is true even if the dependency never gets made.
-- True or false: The rules to
make
a target file will be run if either the target file or the dependencies are modified.
-- True or false: Dependencies in
make
are accessed “lazily”, so that if the dependencies are never actually used when executing a rule, they don’t actually have any impact on the Makefile.
-
-
Why Automation
It often makes sense to break up a task (e.g. “analyze data and turn it into publication ready figures and tables”) into smaller chunks, e.g. “data cleaning” vs “summarizing and plotting” vs “model fitting”. This leads to a pipeline: a system where the code for some tasks (e.g. summarizing and plotting) depend on the output of others (e.g. data cleaning).
@@ -139,6 +126,19 @@
Agenda
+
+
+
Test Your Understanding
+
Use these questions to check your understanding of the material.
+
+- True or False: You’ve opened Terminal, and are now about to run
Rscript
for a second time. Because you haven’t restarted the Terminal, the code will continue to build in the same session as before.
+- You have information in
script1.R
that you’d like to pass to scipt2.R
. True or false: the best way to pass the info to script2.R
is by saving the final workspace from script1.R
in an .RData
or .rds
file, and loading that it into script2.R
.
+- True or False: It’s almost always better to write an
.Rmd
file over an .R
file, because you’re able to interlace markdown.
+- True or false:
make
ing a phony target will always run its rules, whereas make
ing a target file will only run its rules if the output needs updating.
+- True or false: If a dependency file is not present on your computer, you can still call
make
error-free if the dependency is the target of another rule. This is true even if the dependency never gets made.
+- True or false: The rules to
make
a target file will be run if either the target file or the dependencies are modified.
+- True or false: Dependencies in
make
are accessed “lazily”, so that if the dependencies are never actually used when executing a rule, they don’t actually have any impact on the Makefile.
+
Attribution
Written by Vincenzo Coia, with inspiration from Tiffany Timbers for the explanation of Makefiles, as well as the make activity from Shaun Jackman and Jenny Bryan created for this course prior to 2017.
diff --git a/content/notes/notes-b04.Rmd b/content/notes/notes-b04.Rmd
index a0862607..9156bb62 100644
--- a/content/notes/notes-b04.Rmd
+++ b/content/notes/notes-b04.Rmd
@@ -38,6 +38,10 @@ Other dashboard tools besides shiny (but not in R):
- With python: plotly dash. Check out the [main website](https://plotly.com/dash/), or [this Medium post](https://medium.com/plotly/introducing-dash-5ecf7191b503) introducing the tool.
- With javascript: [D3](https://d3js.org/), a tremendously powerful tool with a steep learning curve (esp. if you don't know javascript).
+## Agenda
+
+We are going to be working off of a [slide deck](https://docs.google.com/presentation/d/1dXhqqsD7dPOOdcC5Y7RW--dEU7UfU52qlb0YD3kKeLw/edit#slide=id.p) and [tutorial](https://deanattali.com/blog/building-shiny-apps-tutorial/) written by Dean Attali. This should take two classes.
+
## Test Your Understanding
1. True or False: A shiny app, as a website, still requires an instance of R running in the background. The stat545.stat.ubc.ca website is static: it doesn't require an active session to be running in the background.
@@ -50,9 +54,6 @@ Other dashboard tools besides shiny (but not in R):
```
4. True or False: Since shiny's UI is html, we can manually write the UI by writing HTML in the `HTML()` function.
-## Agenda
-
-We are going to be working off of a [slide deck](https://docs.google.com/presentation/d/1dXhqqsD7dPOOdcC5Y7RW--dEU7UfU52qlb0YD3kKeLw/edit#slide=id.p) and [tutorial](https://deanattali.com/blog/building-shiny-apps-tutorial/) written by Dean Attali. This should take two classes.
diff --git a/content/notes/notes-b04.html b/content/notes/notes-b04.html
index 49d853aa..865b150e 100644
--- a/content/notes/notes-b04.html
+++ b/content/notes/notes-b04.html
@@ -42,6 +42,10 @@
Resources
With javascript: D3, a tremendously powerful tool with a steep learning curve (esp. if you don’t know javascript).
+
+
Agenda
+
We are going to be working off of a slide deck and tutorial written by Dean Attali. This should take two classes.
+
Test Your Understanding
@@ -53,10 +57,6 @@ Test Your Understanding
x <- 1
True or False: Since shiny’s UI is html, we can manually write the UI by writing HTML in the HTML()
function.
-
-
-
Agenda
-
We are going to be working off of a slide deck and tutorial written by Dean Attali. This should take two classes.
diff --git a/content/notes/notes-b05.Rmd b/content/notes/notes-b05.Rmd
index 8793175c..00dca610 100644
--- a/content/notes/notes-b05.Rmd
+++ b/content/notes/notes-b05.Rmd
@@ -23,14 +23,6 @@ Written material:
- [R4DS Chapter 16: regular expressions](https://r4ds.hadley.nz/regexps).
- The stat545.com Chapter 11 on character vectors [has an elaborate discussion on useful resources](https://stat545.com/character-vectors.html#resources-3) for learning more about strings.
-## Test Your Understanding
-
-Use these questions to check your understanding of the material.
-
-1. True or False: The regular expression `[ab][ab]` will match "ab", "aa", and "bb" as possibilities, whereas `[ab]{2}` will only match "aa" or "bb".
-2. True or False: The regular expression `[ab][ab]` will match "ab", "aa", and "bb" as possibilities, whereas `(ab)(ab)` will only match "aa" or "bb".
-3. True or False: The regular expression `^ab` will match "ab" as the first characters to a string, whereas `[^ab]` will match "a" or "b" as being the first character to a string.
-
## Strings
You've used a bunch of strings at this point without knowing explicitly what they are: any time you surround text by `"`, you've been making a *string*: a storage format for text. In R, they are of type "character".
@@ -58,6 +50,14 @@ You can see more examples of special characters and how to escape them in [R4DS
Our main tools for working with strings will be the powerful `stringr` package in the tidyverse paired with regular expressions. We think the best way to start learning these is through the guided tutorial in Worksheet B2.
+## Test Your Understanding
+
+Use these questions to check your understanding of the material.
+
+1. True or False: The regular expression `[ab][ab]` will match "ab", "aa", and "bb" as possibilities, whereas `[ab]{2}` will only match "aa" or "bb".
+2. True or False: The regular expression `[ab][ab]` will match "ab", "aa", and "bb" as possibilities, whereas `(ab)(ab)` will only match "aa" or "bb".
+3. True or False: The regular expression `^ab` will match "ab" as the first characters to a string, whereas `[^ab]` will match "a" or "b" as being the first character to a string.
+
### Agenda
## Class 1
diff --git a/content/notes/notes-b05.html b/content/notes/notes-b05.html
index 70996fd5..9a21b838 100644
--- a/content/notes/notes-b05.html
+++ b/content/notes/notes-b05.html
@@ -28,15 +28,6 @@
Resources
The stat545.com Chapter 11 on character vectors has an elaborate discussion on useful resources for learning more about strings.
-
-
Test Your Understanding
-
Use these questions to check your understanding of the material.
-
-- True or False: The regular expression
[ab][ab]
will match “ab”, “aa”, and “bb” as possibilities, whereas [ab]{2}
will only match “aa” or “bb”.
-- True or False: The regular expression
[ab][ab]
will match “ab”, “aa”, and “bb” as possibilities, whereas (ab)(ab)
will only match “aa” or “bb”.
-- True or False: The regular expression
^ab
will match “ab” as the first characters to a string, whereas [^ab]
will match “a” or “b” as being the first character to a string.
-
-
Strings
You’ve used a bunch of strings at this point without knowing explicitly what they are: any time you surround text by "
, you’ve been making a string: a storage format for text. In R, they are of type “character”.
@@ -57,6 +48,15 @@
Strings
Working with strings
Our main tools for working with strings will be the powerful stringr
package in the tidyverse paired with regular expressions. We think the best way to start learning these is through the guided tutorial in Worksheet B2.
+
+
+
Test Your Understanding
+
Use these questions to check your understanding of the material.
+
+- True or False: The regular expression
[ab][ab]
will match “ab”, “aa”, and “bb” as possibilities, whereas [ab]{2}
will only match “aa” or “bb”.
+- True or False: The regular expression
[ab][ab]
will match “ab”, “aa”, and “bb” as possibilities, whereas (ab)(ab)
will only match “aa” or “bb”.
+- True or False: The regular expression
^ab
will match “ab” as the first characters to a string, whereas [^ab]
will match “a” or “b” as being the first character to a string.
+
Agenda
diff --git a/content/notes/notes-b06.Rmd b/content/notes/notes-b06.Rmd
index 7514d7bf..70bc1a1e 100644
--- a/content/notes/notes-b06.Rmd
+++ b/content/notes/notes-b06.Rmd
@@ -40,15 +40,6 @@ Want to dig deeper? These resources can help.
- [Advanced R Chapter 9: Functionals](https://adv-r.hadley.nz/functionals.html) -- looking at purrr and `map()` from a programming perspective.
- [tidyr's rectangling vignette](https://tidyr.tidyverse.org/articles/rectangle.html) -- for handling deeply nested lists (JSON-style data), similar to tidyr's `pivot_` functions.
-## Test Your Understanding
-
-1. True or False: `map(1:3, ~ function(x) x ^ 2)` returns the list `list(1, 4, 9)`.
-2. You write a function `square()` that squares its input -- but the first thing it does is print a message to the screen! True or False: `map_dbl(1:10, square)` will throw an error, because the output is not a `dbl` (a number) -- it contains the message, too.
-3. True or False: purrr-style functions, starting with `~`, can be used in dplyr's `across()` function, such as `mutate(across(where(is.numeric), ~ .x ^ 2))`, and this function can only take one argument (`.x`)
-4. True or False: If I have 10 tibbles I want to save to file, and they're all stored in a list, the best purrr function to use for saving these to file is `map()`.
-5. True or False: Just as `c(c(1, 2), c(3, 4))` returns the vector of numbers from 1 to 4, `list(list(1, 2), list(3, 4))` returns the list of numbers from 1 to 4.
-6. True or False: `tibble(model = lm(mpg ~ wt, data = mtcars))` doesn't work because it doesn't use a `map` function.
-
## Vectors vs Lists
Here is a list in R; it holds multiple items.
@@ -130,6 +121,17 @@ head(got_lc)
Some characters have one title (e.g. Will); others have more than one title (e.g. Theon Greyjoy). Consequently, the `titles` column is a *list column*, where each entry is a *list* that contains as many or as few strings as we like.
+## Test Your Understanding
+
+1. True or False: `map(1:3, ~ function(x) x ^ 2)` returns the list `list(1, 4, 9)`.
+2. You write a function `square()` that squares its input -- but the first thing it does is print a message to the screen! True or False: `map_dbl(1:10, square)` will throw an error, because the output is not a `dbl` (a number) -- it contains the message, too.
+3. True or False: purrr-style functions, starting with `~`, can be used in dplyr's `across()` function, such as `mutate(across(where(is.numeric), ~ .x ^ 2))`, and this function can only take one argument (`.x`)
+4. True or False: If I have 10 tibbles I want to save to file, and they're all stored in a list, the best purrr function to use for saving these to file is `map()`.
+5. True or False: Just as `c(c(1, 2), c(3, 4))` returns the vector of numbers from 1 to 4, `list(list(1, 2), list(3, 4))` returns the list of numbers from 1 to 4.
+6. True or False: `tibble(model = lm(mpg ~ wt, data = mtcars))` doesn't work because it doesn't use a `map` function.
+
+___
+
## Your turn: Worksheet B3, Parts 2 and 3
We think the best way to learn how to make and work with list columns (and get a taste for where they can be really useful!) is to jump back into the worksheet.
diff --git a/content/notes/notes-b06.html b/content/notes/notes-b06.html
index ed440c57..366beae3 100644
--- a/content/notes/notes-b06.html
+++ b/content/notes/notes-b06.html
@@ -40,17 +40,6 @@
Resources
tidyr’s rectangling vignette – for handling deeply nested lists (JSON-style data), similar to tidyr’s pivot_
functions.
-
-
Test Your Understanding
-
-- True or False:
map(1:3, ~ function(x) x ^ 2)
returns the list list(1, 4, 9)
.
-- You write a function
square()
that squares its input – but the first thing it does is print a message to the screen! True or False: map_dbl(1:10, square)
will throw an error, because the output is not a dbl
(a number) – it contains the message, too.
-- True or False: purrr-style functions, starting with
~
, can be used in dplyr’s across()
function, such as mutate(across(where(is.numeric), ~ .x ^ 2))
, and this function can only take one argument (.x
)
-- True or False: If I have 10 tibbles I want to save to file, and they’re all stored in a list, the best purrr function to use for saving these to file is
map()
.
-- True or False: Just as
c(c(1, 2), c(3, 4))
returns the vector of numbers from 1 to 4, list(list(1, 2), list(3, 4))
returns the list of numbers from 1 to 4.
-- True or False:
tibble(model = lm(mpg ~ wt, data = mtcars))
doesn’t work because it doesn’t use a map
function.
-
-
Vectors vs Lists
Here is a list in R; it holds multiple items.
@@ -68,21 +57,21 @@
Vectors vs Lists
-
Vectors |
Lists |
-
+
Access elements with square brackets [] |
Access elements with [[]] |
-
+
Each element must be an atomic data type (i.e. a single value) |
Elements can be anything, even another list or another vector |
-
+
Each element has to be of the same type |
Elements can be as different as you like |
@@ -142,6 +131,18 @@ List Columns
## 6 Chett Male <chr [1]>
Some characters have one title (e.g. Will); others have more than one title (e.g. Theon Greyjoy). Consequently, the titles
column is a list column, where each entry is a list that contains as many or as few strings as we like.
+
+
Test Your Understanding
+
+- True or False:
map(1:3, ~ function(x) x ^ 2)
returns the list list(1, 4, 9)
.
+- You write a function
square()
that squares its input – but the first thing it does is print a message to the screen! True or False: map_dbl(1:10, square)
will throw an error, because the output is not a dbl
(a number) – it contains the message, too.
+- True or False: purrr-style functions, starting with
~
, can be used in dplyr’s across()
function, such as mutate(across(where(is.numeric), ~ .x ^ 2))
, and this function can only take one argument (.x
)
+- True or False: If I have 10 tibbles I want to save to file, and they’re all stored in a list, the best purrr function to use for saving these to file is
map()
.
+- True or False: Just as
c(c(1, 2), c(3, 4))
returns the vector of numbers from 1 to 4, list(list(1, 2), list(3, 4))
returns the list of numbers from 1 to 4.
+- True or False:
tibble(model = lm(mpg ~ wt, data = mtcars))
doesn’t work because it doesn’t use a map
function.
+
+
+
Your turn: Worksheet B3, Parts 2 and 3
We think the best way to learn how to make and work with list columns (and get a taste for where they can be really useful!) is to jump back into the worksheet.
diff --git a/static/notes/notes-a06_files/figure-html/unnamed-chunk-10-1.png b/static/notes/notes-a06_files/figure-html/unnamed-chunk-10-1.png
index ed3ad9b9..a0e9c6b3 100644
Binary files a/static/notes/notes-a06_files/figure-html/unnamed-chunk-10-1.png and b/static/notes/notes-a06_files/figure-html/unnamed-chunk-10-1.png differ
diff --git a/static/notes/notes-a06_files/figure-html/unnamed-chunk-12-1.png b/static/notes/notes-a06_files/figure-html/unnamed-chunk-12-1.png
index 0e7a494b..36a75c56 100644
Binary files a/static/notes/notes-a06_files/figure-html/unnamed-chunk-12-1.png and b/static/notes/notes-a06_files/figure-html/unnamed-chunk-12-1.png differ
diff --git a/static/notes/notes-a06_files/figure-html/unnamed-chunk-14-1.png b/static/notes/notes-a06_files/figure-html/unnamed-chunk-14-1.png
index 4f80e1d6..86431e1f 100644
Binary files a/static/notes/notes-a06_files/figure-html/unnamed-chunk-14-1.png and b/static/notes/notes-a06_files/figure-html/unnamed-chunk-14-1.png differ
diff --git a/static/notes/notes-a06_files/figure-html/unnamed-chunk-3-1.png b/static/notes/notes-a06_files/figure-html/unnamed-chunk-3-1.png
index 353d603b..164b0d5d 100644
Binary files a/static/notes/notes-a06_files/figure-html/unnamed-chunk-3-1.png and b/static/notes/notes-a06_files/figure-html/unnamed-chunk-3-1.png differ
diff --git a/static/notes/notes-a06_files/figure-html/unnamed-chunk-5-1.png b/static/notes/notes-a06_files/figure-html/unnamed-chunk-5-1.png
index 6a9a0131..ced712c0 100644
Binary files a/static/notes/notes-a06_files/figure-html/unnamed-chunk-5-1.png and b/static/notes/notes-a06_files/figure-html/unnamed-chunk-5-1.png differ
diff --git a/static/notes/notes-a06_files/figure-html/unnamed-chunk-6-1.png b/static/notes/notes-a06_files/figure-html/unnamed-chunk-6-1.png
index 27b668c4..e294bd66 100644
Binary files a/static/notes/notes-a06_files/figure-html/unnamed-chunk-6-1.png and b/static/notes/notes-a06_files/figure-html/unnamed-chunk-6-1.png differ
diff --git a/static/notes/notes-a06_files/figure-html/unnamed-chunk-7-1.png b/static/notes/notes-a06_files/figure-html/unnamed-chunk-7-1.png
index 353d603b..164b0d5d 100644
Binary files a/static/notes/notes-a06_files/figure-html/unnamed-chunk-7-1.png and b/static/notes/notes-a06_files/figure-html/unnamed-chunk-7-1.png differ
diff --git a/static/notes/notes-a06_files/figure-html/unnamed-chunk-9-1.png b/static/notes/notes-a06_files/figure-html/unnamed-chunk-9-1.png
index 8b219edb..c3aeb5b9 100644
Binary files a/static/notes/notes-a06_files/figure-html/unnamed-chunk-9-1.png and b/static/notes/notes-a06_files/figure-html/unnamed-chunk-9-1.png differ
diff --git a/static/notes/notes-a09_files/figure-html/unnamed-chunk-21-1.png b/static/notes/notes-a09_files/figure-html/unnamed-chunk-21-1.png
index f84d3a1f..cbec5977 100644
Binary files a/static/notes/notes-a09_files/figure-html/unnamed-chunk-21-1.png and b/static/notes/notes-a09_files/figure-html/unnamed-chunk-21-1.png differ