class: center, middle, inverse, title-slide # EHEC, Introduction to R ## Orientation ### Alex Hollingsworth, Grant McDermott, and Kelli Marquardt ### Indiana University | University of Oregon | Chicago FED ### 14 July 2021 --- class: inverse, center, middle # Prologue --- ## Requirements ☑ Installed [R](https://www.r-project.org/). ☑ Installed [RStudio](https://www.rstudio.com/products/rstudio/download/preview/). -- Some optional (not necessary for today!) things that I recommend if you plan to use R going forward: - **Windows:** Install [Rtools](https://cran.r-project.org/bin/windows/Rtools/). - **Mac:** Install [XQuartz](https://www.xquartz.org/) and the [R MacOS toolchain](https://github.com/rmacoslib/r-macos-rtools#how-do-i-use-the-installer). -- These "extras" are mostly for when you want to build R packages directly from GitHub (e.g. development versions) that rely on compiled code (e.g. C++) --- ## Quick tour of RStudio (Live session) --- class: inverse, center, middle # Why use / learn R? --- ## Pros 1. **Free.** Free as beer, free as in speech. -- 2. **Fast.** For many common operations, the R equivalents of (even optimised) Stata commands can be orders of magnitude faster. Examples: [reshaping](https://grantmcdermott.com/reshape-benchmarks/), [collapsing](https://twitter.com/grant_mcdermott/status/1402718339768545280), [HDFE regression](https://grantmcdermott.com/better-way-adjust-SEs/#benchmarking). -- 3. **Flexible.** A _huge_ array of packages and ancillary features. GIS, Machine learning, databases, version control (git), websites and apps, documents, etc. etc. -- 4. **~~Fobs~~Jobs.** Excellent outside options for a lot of econ graduates going into non-academic positions. --- ## Cons 1. **Unfamiliarity.** Learning a new language (can) suck. Go easy on yourself and R. - Quick tip: Stata thinks quite differently about programming and code than a lot of other languages. This doesn't make it bad! But it does mean that you might get stuck by trying to re-purpose your exact Stata workflow in R. 2. **Tyranny of information/choice.** R invariably has multiple ways to do exactly the same thing. Example: Assignment with `<-` and/or `=`. - Quick tip: Just pick whatever method/package looks easiest to you. At the same time, don't be scared to mix and match. -- Meta thoughts: Pick whatever workflow works for you! --- ## Help _Very_ friendly communities and forums online. SO, RLadies, Twitter, etc. You can also look at the help documentation. ```r ?plot example(plot) library(ggplot2) example(geom_contour) demo("graphics", package = "graphics") ``` Most packages also provide _vignettes_ (mini use guides). [Example](https://lrberge.github.io/fixest/articles/fixest_walkthrough.html). --- ## Some other R differences/gotchas coming from Stata - Multiple objects can exist in memory. This is the most common source of errors I see among newcomers. - Log files aren't common (see point above), although can be used. - You need to load packages into memory when you want to use them. -- - Speaking of which, let's get our hands dirty with some examples...