class: center, middle, inverse, title-slide # Lab 01: R you Ready? ### 2019-08-29 --- layout: true <div class="my-footer"> <span> <img src = "img/dsbox-logo.png" width = "30"> </img> Slides adapted from <a href="https://datasciencebox.org" target="_blank">datasciencebox.org</a> by Dr. Lucy D'Agostino McGowan </span> </div> --- class: center, middle # Welcome to lab --- # Agenda - Follow up - Meet the toolkit - Demos - Lab 01 on your own --- ## Join campuswire Go to [bit.ly/sta-212-f19-discuss-join](http://bit.ly/sta-212-f19-discuss-join) and sign up. --- ## <i class="fas fa-laptop"></i> Practice answering a question or posting in a channel - Click on "Class feed" on the top left. You should see a post from me titled `Hello!` - Practice responding to this post, up-voting it, etc. - Click on "Rooms" then `#general` - Practice posting here - post a fun fact about your self, respond with an emoji 👍, etc --- ## Toolkit ![toolkit](img/01/toolkit.png) - Scriptability `\(\rightarrow\)` R - Literate programming (code, narrative, output in one place) `\(\rightarrow\)` R Markdown --- class: center, middle # R and RStudio --- ## What is R/RStudio? - R is a statistical programming language - RStudio is a convenient interface for R (an integreated development environment, IDE) - At its simplest:<sup>➥</sup> - R is like a car’s engine - RStudio is like a car’s dashboard <img src="img/01/engine-dashboard.png" width="420" style="display: block; margin: auto;" /> .footnote[ ➥ Source: [Modern Dive](https://moderndive.com/) ] --- ## Let's take a tour - R / RStudio .center[ ![](img/demo.png) ] Concepts introduced: - Console - Using R as a calculator - Environment - Loading and viewing a data frame - Accessing a variable in a data frame - R functions --- ## R essentials A short list (for now): - Functions are (most often) verbs, followed by what they will be applied to in parantheses: ```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 the `library` function, once per session: ```r install.packages("package_name") library(package_name) ``` --- ## tidyverse .pull-left[ ![](img/01/tidyverse.png) ] .pull-right[ .center[ [tidyverse.org](https://www.tidyverse.org/) ] - The tidyverse is an opinionated collection of R packages designed for data analysis and data science. - All packages share an underlying philosophy and a common grammar. ] --- class: center, middle # R Markdown --- ## R Markdown - Fully reproducible reports -- each time you knit the analysis is run from the beginning - Simple markdown syntax for text - Code goes in chunks, defined by three backticks, narrative goes outside of chunks --- ## Let's take a tour - R Markdown .center[ ![](img/demo.png) ] Concepts introduced: - Copying a project of mine - Knitting documents - R Markdown and (some) R syntax --- ## <i class="fas fa-laptop"></i> `Happy Little Clouds Example` -- <br> - Go to RStudio Cloud and click on `Happy Little Clouds Example` - Open and knit the R Markdown document. --- ## R Markdown help .pull-left[ .center[ [R Markdown cheat sheet](https://github.com/rstudio/cheatsheets/raw/master/rmarkdown-2.0.pdf) ] ![](img/01/rmd-cheatsheet.png) ] .pull-right[ .center[ Markdown Quick Reference `Help -> Markdown Quick Reference` ] ![](img/01/md-cheatsheet.png) ] --- ## Workspaces Remember this, and expect it to bite you a few times as you're learning to work with R Markdown: The workspace of your R Markdown document is separate from the Console! - Run the following in the console ```r x <- 2 x * 3 ``` -- .question[ All looks good, eh? ] -- - Then, add the following chunk in your R Markdown document ```r x * 3 ``` -- .question[ What happens? Why the error? ] --- ## How will we use R Markdown? - Every assignment / report / project / etc. is an R Markdown document - You'll always have a template R Markdown document to start with - The amount of scaffolding in the template will decrease over the semester - You will turn in the .html file on Sakai --- ## Lab 01 - Lab instructions are posted on the course website under `</>` + Let's go find today's! .center[ # [bit.ly/sta-212-f19](https://bit.ly/sta-212-f19) ]