class: center, middle, inverse, title-slide # Meet the Toolkit ## Intro to Data Science ### Shawn Santo ### 01-14-20 --- ## Agenda - Reproducible data analysis <br/> - R and RStudio <br/> - R Markdown <br/> - Git and GitHub --- class: center, middle, inverse # Reproducible data analysis --- ## Reproducibility checklist What does it mean for a data analysis to be "reproducible"? -- **Near-term goals:** - Are tables and figures reproducible from the code and data? - Does code actually do what you think it does? - In addition to what was done, is it clear **why** it was done? (e.g., how were parameter settings chosen?) -- **Long-term goals:** - Can the code be used for updates to the current data? - Can the code be used for other data? - Can you extend the code to do other things? --- ## Toolkit <img src="img/01/toolkit.png" width="70%" style="display: block; margin: auto;" /> - Scriptability `\(\rightarrow\)` R <br/><br/> - Literate programming (code, narrative, output in one place) `\(\rightarrow\)` R Markdown <br/><br/> - Version control `\(\rightarrow\)` Git / GitHub --- class: center, middle, inverse # R and RStudio --- ## What is R/RStudio? - R is a statistical programming language. <br/><br/> - RStudio is a convenient interface for R (an integrated development environment, IDE). <br/><br/> - At its simplest: - R is like a car’s engine - RStudio is like a car’s dashboard <img src="img/01/engine-dashboard.png" width="70%" style="display: block; margin: auto;" /> The RStudio interface makes working with R much easier. *Source*: [Modern Dive](https://moderndive.com/) --- ## R essentials (a short overview) **Functions** are (most often) verbs, followed by what they will be applied to in parentheses: ```r do_this(to_this) do_that(to_this, to_that, with_those) ``` -- **Columns** (variables) in data frames are accessed with `$`: ```r dataframe$var_name ``` -- **Packages** are installed with the `install.packages` function and loaded with function `library()` once per session: ```r install.packages("package_name") library(package_name) ``` --- ## Package `tidyverse` .pull-left[ ![](img/01/tidyverse.png) [tidyverse.org](https://www.tidyverse.org/) ] .pull-right[ - The tidyverse is an opinionated collection of R packages designed for data science. <br/><br/><br/> - All packages share an underlying philosophy and a common grammar. ] --- class: center, middle, inverse # R Markdown --- ## R Markdown - Fully reproducible reports -- the analysis is run from the beginning each time you knit <br/><br/> - Simple Markdown syntax for text <br/><br/> - Code goes in chunks, defined by three backticks, narrative goes outside of chunks --- ## RStudio and R Markdown tour First, recall "The murky tale of Flint’s deceptive water data" - How many samples were taken from each sampled home? - What is the EPA action level? -- Live demo - https://github.com/sta199-sp20-001 - https://rstudio.cloud/ -- Concepts introduced: - Cloning a project from GitHub to RStudio Cloud - Knitting documents - R Markdown and (some) R syntax - Console - Using R as a calculator - Environment - Loading and viewing a data frame - Accessing a variable in a data frame - R functions --- ## R Markdown tips **Resources** - [R Markdown cheat sheet](https://github.com/rstudio/cheatsheets/raw/master/rmarkdown-2.0.pdf) - In RStudio Cloud, Markdown Quick Reference: - `Help -> Markdown Quick Reference` <br><br> -- **Remember**: The workspace of the R Markdown document is separate from the console --- ## Workspace vs. console Run the following in your console. ```r x <- 2 x * 3 ``` -- Then, add the following chunk in your R Markdown document and knit. ```r x * 3 ``` <br/><br/> -- What happens? Why the error? --- ## How will we use R Markdown? - Every homework, lab, and project will involve an R Markdown document. <br/><br/> - You'll always have a template R Markdown document to start with; however, the amount of scaffolding in the template will decrease over the semester. --- class: center, middle, inverse # Git and GitHub --- ## Version control - We introduced GitHub as a platform for collaboration - But it's much more than that... - It's actually designed for version control --- ## Versioning <img src="img/01/lego-steps.png" width="80%" style="display: block; margin: auto;" /> --- ## Versioning We can add human readable messages. <img src="img/01/lego-steps-commit-messages.png" width="80%" style="display: block; margin: auto;" /> --- ## Git and GitHub tips - **Git** is a version control system, similar to “Track Changes” features from Microsoft Word. <br/><br/> -- - **GitHub** is the home for your Git-based projects on the internet (like DropBox but much better). <br/><br/> -- - There are a lot of Git commands and very few people know them all; most of the time you will use ```bash git add git commit git push git pull ``` --- ## Git and GitHub tips - We will be using git and interfacing with GitHub through RStudio <br/><br/> - If you Google for help you might come across methods for doing these things in the command line -- skip that and move on to the next resource unless you feel comfortable trying it out. <br/><br/><br/><br/> -- - There is a great resource for working with git and R: [happygitwithr.com](http://happygitwithr.com/). <br/><br/> - Some of the content in there is beyond the scope of this course, but it's a good place to look for help. --- ## Git and GitHub live demo - Concepts introduced: - Connect an R project to GitHub repository - Working with a local and remote repository - Making a change locally, committing, and pushing <br/><br/> - In Lab 01 you will go through the full version control cycle. As the semester progresses we will guide you in using Git/GitHub in a team-based environment. --- ## Recap Can you answer these questions? - What is a reproducible data analysis, and why is it important? <br/><br/> - What is version control, and why is it important? <br/><br/> - What is R vs. RStudio? <br/><br/> - What is git vs. GitHub? --- ## Before next class - Accept the invite to join `sta199-sp20-001` on GitHub. - Begin the next reading. - If you did not do so in Lab 00, please complete the "getting to know you" survey: http://bit.ly/sta199-sp20-survey --- ## References 1. McConville, C. (2019). Statistical Inference via Data Science. Moderndive.com. Retrieved from https://moderndive.com/