class: center, inverse # Teaching tips for gentle R introductions <img src="r_first_then.jpg" width="70%" /> ## Allison Horst (Bren School) ahorst@ucsb.edu | Twitter: [@allison_horst](https://twitter.com/allison_horst) | Web: [allisonhorst.com](https://www.allisonhorst.com/) --- # Hello! ## A little about me: - πΏ Assistant Teaching Professor - Environmental Data Science - π¨βπ« 10 years teaching in R (introductory & advanced courses) - π Bren & UCSB students from diverse backgrounds - π©βπ¨ RStudio Artist-in-Residence (2019 - 2020) - π Workshops in industry, academia, learning communities --- class: middle ## Random tip 1: add emoji in R Markdown Use the [emo](https://github.com/hadley/emo) package to add emoji in R Markdown. ```r emo::ji("penguin") ``` ``` ## π§ ``` Use `View(jis)` to check out all the specific emoji names. --- # Why this talk? - π Data science / coding skills ubiquitously valuable - π©βπ« Instructors and TAs incorporating R into courses - π Teaching R (or any programming) can be a beast - π A lot of things that are useful for teaching are also useful for data analysis, communication & more **Important:** There are *many* good ways to teach R & data science. Pick what works well for you and your students! --- # 4-3-2-1...go outline! - ### 4οΈβ£ strategies to welcome hesitant students - ### 3οΈβ£ tools to make your life easier - ### 2οΈβ£ platforms to minimize installation barriers - ### 1οΈβ£ lesson learned <img src="go-r-teachers.png" width="20%" style="display: block; margin: auto;" /> --- class: inverse # 4οΈβ£ strategies to welcome hesitant students <img src="scary-r.png" width="80%" style="display: block; margin: auto;" /> --- ## First interaction with R? ```r vec <- c(1, 5, 10, 20) vec[2] ``` ``` ## [1] 5 ``` ```r calc_volume <- function(moles, R, temp, pressure) { (moles * R * temp) / pressure } ``` ## π€’ --- class: inverse ## 1. Create early wins <img src="welcome_to_rstats.png" width="50%" style="display: block; margin: auto;" /> --- class: left, middle "On the first day of the course...students are presented with a fully functional R Markdown document...that they can knit to produce an in-depth data visualization. Then, **by updating just one parameter in the R Markdown document, they can produce a new report with a new data visualization**." *From* [A Fresh Look at Introductory Data Science](https://www.tandfonline.com/doi/full/10.1080/10691898.2020.1804497) *by Mine Cetinkaya-Rundel and Victoria Ellison, Journal of Statistics and Data Science Education (Vol. 29, 2021)* --- class: inverse ## 2. Engage more students with creative activities <img src="rstudio-artist.jpg" width="50%" style="display: block; margin: auto;" /> --- class: center, top, inverse <img src="ds-venn.png" width="45%" /> .footnote[ From the [Data Science at the Urban Institute](https://urban-institute.medium.com/what-is-data-science-the-urban-institute-b5e4b3ff9cc2) ] --- ## Example Activity 1: Do your data viz worst <div class="figure" style="text-align: center"> <img src="simpsons-viz.png" alt="By Jessica West, Bren MESM Class of 2023" width="60%" /> <p class="caption">By Jessica West, Bren MESM Class of 2023</p> </div> --- ```r ggplot(data = space, aes(x = agency, y = launch_year)) + annotation_custom(rasterGrob(img, width = unit(1,"npc"), height = unit(1,"npc")), -Inf, Inf, -Inf, Inf) + geom_point() + theme( plot.background = element_rect(fill = "yellow"), plot.title = element_text(size = 30, hjust = 0.25), plot.subtitle = element_text(size = 20, hjust = 0.75, color = "red", family = "serif"), plot.caption = element_text(size = 10, face = "italic", angle = 25), axis.title.x = element_text(face = "bold.italic", color = "blue"), axis.title.y = element_text(family = "mono", face = "bold", size = 20, hjust = 0.25), axis.text = element_text(face = "italic", size = 15), axis.text.x.bottom = element_text(angle = 180), panel.background = element_rect(fill = 'lightblue', colour = 'darkred', size = 4), panel.border = element_rect(fill = NA, color = "green", size = 2), panel.grid.major.x = element_line(color = "purple", linetype = 2), panel.grid.minor.x = element_line(color = "orange", linetype = 3), panel.grid.minor.y = element_blank(), strip.background = element_rect(fill = "magenta"), strip.text.y = element_text(color = "white"), strip.placement = "outside") + labs(x = "Agency", y = "Y", title = "Agency L@unch D@tes", subtitle = "Some time before today", caption = "Data source: Space Force?") ``` --- ## Example Activity 2: Make some aRt For example, Danielle Navarro's {flametree} package: ```r library(flametree) dat <- flametree_grow(time = 7, trees = 15) p <- dat %>% flametree_plot( background = "gray10", palette = c("antiquewhite", "coral", "cyan4", "goldenrod"), style = "nativeflora" ) ``` --- class: inverse, center, middle ![](qmss_r_teaching_slides_files/figure-html/unnamed-chunk-13-1.png)<!-- --> --- class: inverse ## 3. Help them personalize their kitchen <img src="decorate-r.jpg" width="60%" style="display: block; margin: auto;" /> --- ## Minimal effort, big impact ideas: - Update IDE theme π - R Markdown + visual editor π - Rainbow parentheses π - R Projects for easier file paths --- ## Random tip 2 ## ...wait you AREN'T using rainbow parentheses? In RStudio (version >= 1.4): *Tools > Global Options > Code > Display > Rainbow parentheses* <img src="rainbow-parentheses.png" width="90%" /> --- ## 4. Write code together - You talk, ask & type, then they type - bit by bit - Bring annotated key for yourself! - Make keys available* before and after for everyone \*Keep this in mind in the next section of the talk! --- ### Talking through code: example How might I teach this code with beginners who have been **exposed** to these functions, but who will absolutely not in any universe remember how to write them out for at least several weeks? ```r library(tidyverse) library(palmerpenguins) chinstrap <- penguins %>% filter(species == "Chinstrap") %>% mutate(body_mass_kg = body_mass_g / 1000) %>% rename(season_start = year) ``` --- ## Random tip 3: penguins with a purpose! .pull-left[ <img src="palmerpenguins.png" width="60%" style="display: block; margin: auto;" /> ] .pull-right[ <font size=5.5> The <i>iris</i> dataset was published by RA Fisher in <i>The Annals of Eugenics</i> (1936). The penguins data in the {palmerpenguins} R package is a near drop-in replacement, plus: <ul> <li> No eugenics history <li> Recent data (2007 - 2009) by Dr. Kristen B. Gorman <li> Unequal sample size + some missing values <li> Complete metadata </ul> </font> ] Learn more! [allisonhorst.github.io/palmerpenguins/](https://allisonhorst.github.io/palmerpenguins/) --- ## Also comes with art + pictures! "Everybody loves penguins." - Dr. Kristen Gorman .pull-left[ <img src="penguins.png" width="100%" style="display: block; margin: auto;" /> ] .pull-right[ <img src="gorman-penguins.png" width="100%" style="display: block; margin: auto;" /> ] See [more photos](https://docs.google.com/presentation/d/1DFJLXYRJ2kWw6AFkJu7MclFPr8zkqD-PHh5bs4xcr3Y/edit) of the Palmer Archipelago penguins! --- # 4-3-2-1...go outline! - ### 4οΈβ£ strategies to welcome hesitant students β - ### 3οΈβ£ tools to make your life easier - ### 2οΈβ£ platforms to minimize installation barriers - ### 1οΈβ£ lesson learned <img src="go-r-teachers.png" width="20%" style="display: block; margin: auto;" /> --- ## 3οΈβ£ tools that might make your life easier 1. π [{xaringan}](https://github.com/yihui/xaringan) for slides 2. π» [GitHub Pages](https://pages.github.com/) to share materials 3. π Use existing educational resources --- ## [{xaringan}](https://github.com/yihui/xaringan) by Yihui Xie ### /ΚaΛ.'riΕ.Ι‘an/ Slides with code and outputs, easily updated & shared. ### (...because copying and pasting screenshots of code is a tedious bummer that doesn't model good practices for reproducibility & automation) --- ## These slides are all made in R Markdown Let's see how! ```r install.packages("xaringan") ``` New R Markdown > From Template > Xaringan > π§Ά ! --- ## 2. [GitHub Pages](https://pages.github.com/) to share lab keys ### π© Tired: Save, upload, edit, delete, reupload, repeat. ### π Wired: Edit, push. --- ## Using GitHub pages to make any .Rmd a web page In a GitHub repo named `bananas` (owned by user "giraffe"), enable GitHub pages, choose source (Settings > Pages > from branch): - A file named `index.html` will be live at `giraffe.github.io/bananas` - Any other html will be published with file name as an added slug (e.g. `giraffe.github.io/bananas/taco.html`) --- ## So if your repo looks like this: <img src="repo-gh-pages.png" width="70%" /> --- ## And you've done this: Settings > Pages > (update source) <img src="gh-pages.png" width="80%" /> --- ## Then those .htmls will be live at: - `username.github.io/repo-name` - `username.github.io/repo-name/file-name.html` For the examples shown on previously slides (username = "allisonhorst", repo name = "gh-pages-demo") and with two files, index.html and demo-key.html, those will be published respectively at: - allisonhorst.github.io/gh-pages-demo/ - allisonhorst.github.io/gh-pages-demo/demo-key.html --- ## 3. Use existing teaching materials - [{swirl}](https://swirlstats.com/) package to "learn R, in R" with existing lessons, or you can modify / create your own lessons! - Tutorials in RStudio - [Data science in a box](https://datasciencebox.org/index.html) by Mine Cetinkaya-Rundel - [The big book of R](https://www.bigbookofr.com/) by Oscar Baruffa - [R for Excel Users](https://rstudio-conf-2020.github.io/r-for-excel/) 2-day workshop by Lowndes & Horst --- # 4-3-2-1...go outline! - ### 4οΈβ£ strategies to welcome hesitant students β - ### 3οΈβ£ tools to make your life easier β - ### 2οΈβ£ platforms to minimize installation barriers - ### 1οΈβ£ lesson learned <img src="go-r-teachers.png" width="20%" style="display: block; margin: auto;" /> --- ## 2οΈβ£ platforms to minimize installation barriers - {learnr} - RStudio Cloud --- ## [{learnr}](https://rstudio.github.io/learnr/) "The learnr package makes it easy to turn any R Markdown document into an interactive tutorial. Tutorials consist of content along with interactive components for checking and reinforcing understanding. Tutorials automatically preserve work done within them, so if a user works on a few exercises or questions and returns to the tutorial later they can pick up right where they left off." --- ## Example learnr tutorial Missing data tutorial: https://allisonhorst.shinyapps.io/missingexplorer/ <img src="missing-home.png" width="60%" style="display: block; margin: auto;" /> --- Include activities, examples, quizzes, hints, videos and more! <img src="missing-activities.png" width="80%" style="display: block; margin: auto;" /> See a bunch of other examples here: https://rstudio.github.io/learnr/ --- ## You can make one too! - Install the {learnr} package - New file > R Markdown > From Template > Interactive Tutorial <img src="pam-gif.gif" width="40%" style="display: block; margin: auto;" /> --- ## RStudio Cloud - Share materials in an R project with a link! - No git / GitHub needed "RStudio Cloud is a hosted version of RStudio in the cloud that makes it easy for professionals, hobbyists, trainers, teachers and students to do, share, teach and learn data science using R. Create your analyses using RStudio directly from your browser - there is no software to install and nothing to configure on your computer." ### Let's check it out! --- ### Don't miss out on the [RStudio Cloud primers](https://rstudio.cloud/learn/primers) <img src="rstudio-cloud-primers.png" width="75%" style="display: block; margin: auto;" /> --- # 4-3-2-1...go outline! - ### 4οΈβ£ strategies to welcome hesitant students β - ### 3οΈβ£ tools to make your life easier β - ### 2οΈβ£ platforms to minimize installation barriers β - ### 1οΈβ£ lesson learned <img src="go-r-teachers.png" width="20%" style="display: block; margin: auto;" /> --- ## 1οΈβ£ big lesson learned ### Curiosity and resourcefulness are learning outcomes. <img src="code-hero.png" width="40%" style="display: block; margin: auto;" /> --- # 4-3-2-1...done! - ### 4οΈβ£ strategies to welcome hesitant students β - ### 3οΈβ£ tools to make your life easier β - ### 2οΈβ£ platforms to minimize installation barriers β - ### 1οΈβ£ lesson learned β <img src="go-r-teachers.png" width="20%" style="display: block; margin: auto;" /> --- class: inverse, center ## Some teachers I learn from: [Mine Cetinkaya-Rundel](https://mine-cr.com/) | [Tiffany Timbers](https://www.tiffanytimbers.com/) | [Julia Lowndes](https://jules32.github.io/) | [Jenny Bryan](https://jennybryan.org/) | [Alison Hill](https://www.apreshill.com/) | [Greg Wilson](https://third-bit.com/) | [Kelly Bodwin](https://www.kelly-bodwin.com/) ... + many more # I welcome you to reach out! ahorst@ucsb.edu | @allison_horst | www.allisonhorst.com ## Thank you QMSS!