2 My intro to R recommendations:
- There’s a whole history/background with R, but here’s what I think is the most important thing to know: there are 2 popular dialects in R, and you should become familiar with both.
- Base R: the base language, which can be pretty esoteric and mind-bending (but totally worth it)
- The tidyverse: a group of R packages that simplify working in R. There are Base R champions that dislike the tidyverse, but I like it and highly recommend using the tidyverse to bridge the gap between beginner and advanced understanding of R.
My intro to R recommendations (summarized):
- Read through the links below before starting (at least glance through them)
- New to R? Kickstart your learning and career with these 6 steps! – paulvanderlaken.com (learn R)
- Especially R for Data Science (tidyverse)
- Read this: Happy Git and GitHub for the useR (workflow)
- Read this: Project-oriented workflow - Tidyverse (workflow)
- Read this: A perfect RStudio layout (Ilya Kashnitsky, 2018) (workflow)
2.1 Read this “New to R” article:
- New to R Kickstart your learning and career with these 6 steps! – paulvanderlaken.com (Paul van der Laken, 2017) (where I got most of these recommendations)
2.2 Start by setting up R:
- Create a directory for your R learning stuff somewhere on your computer.
- Download A (very) short introduction to R by Paul Torfs and Claudia Bauer
- Read the introduction and follow the steps. It will help you install all R software on your own computer and familiarize you with the standard data types.
- We’ll talk about your “R Workflow” at the end of this article
2.3 Spend some time learning the basics of Base R:
- You got a taste of Base R in A (very) short introduction to R. Follow that with Swirl and Yarrr!
- Swirl - a course with 15 modules that provide mastery of the basics of R in the environment itself.
- Open up your RStudio and enter the two lines of code below in your console window.
install.packages('swirl') #download swirl package
library(swirl) #load in swirl package
- Swirl (webpage) will automatically start and after a couple of prompts you will be able to choose the learning course called 1: R Programming: The basics of programming in R.
- YaRrr! The Pirate’s Guide to R (Phillips, 2017) starting in chapter 3.
- Start with chapter 3. It’s a fun book and will provide you with more knowledge on how to program custom functions, loops, and some basic statistical modelling techniques – the thing R was actually designed for.
2.4 Follow that by learning the tidyverse:
- Work through R for Data Science (Grolemund & Wickham, 2017)
- Here’s a nice overview of the tidyverse: tidyverse 101: Simplifying life for useRs – paulvanderlaken.com
- Oh, and I found this quite useful: R for Data Science Solutions
2.5 As you go about learning R, think about your “R workflow”" (I recommend three articles):
- Happy Git and GitHub for the useR (Bryan, 2018) (using git with R)
- New Project Workflow: New project, GitHub first
- Create a new github repository repository
- Click “Clone or download” -> copy link
- in RStudio -> File -> New Project -> Version Control -> Git -> paste url
- Daily Workflow:
- Start day with the “Pull” button from the “Git” tab in RStudio (make sure you are starting with the current versions)
- Save/Commit regularly with informative commit changes
- Amend Commits when you make incremental saves. Do commits for separate changes.
- New Project Workflow: New project, GitHub first
- A perfect RStudio layout (Ilya Kashnitsky, 2018) (My current preferred layout)
- Adjust in “Tools” –> “Global options” –> “Pane layout”:
- Top Left: Source
- Bottom Left: History (then collapse)
- Top Right: Console
- Bottom Right: Everything else
- Adjust in “Tools” –> “Global options” –> “Pane layout”:
- Project-Oriented Workflow (Bryan 2017) (how to think about projects in R)
- Organize each logical project into a folder on your computer (this is also where you put your .here, .git, and/or .Rproj files)
- Directories:
- Create all paths relative to the top-level directory.
- Whenever you work on this project, launch the R process from the project’s top-level directory. If you launch R from the shell,
cd
to the correct folder first.
- Write every script assuming it will be run in a fresh R process:
- User-level setup: Do not save .RData when you quit R and don’t load .RData when you fire up R.
- Don’t do things in your .Rprofile that affect how R code runs, such as loading a package like dplyr or ggplot or setting an option such as stringsAsFactors = FALSE.
- Daily work habit: Restart R very often and re-run your under-development script from the top.