D-Lab's R Fundamentals Workshop
This repository contains the materials for D-Lab's R Fundamentals workshop. No prior experience with R is required.
Workshop Goals
This interactive workshop series is your complete introduction to programming in R for people with little or no previous programming experience. It covers the basics of using RStudio, creating variables, working with data frames, and starting to analyse your data using summary statistics and data visualization.
Learning Objectives
After completing this workshop series you will be able to:
- Navigate R Studio
- Open data in R and work with it in data frames using tidyverse
- Distinguish between different variable types
- Visualize data using ggplot
- Inspect documentation to deal with error messages
This workshop does not cover the following:
- Advanced data manipulation and cleaning - this is covered in R Data Wrangling
- Extensive data visualization - this is covered in R Data Visualization
Workshop Structure
R Fundamentals has 4 parts. Each of the parts takes 2 hours, and is delivered in a lecture-style coding walk through interrupted by challenge problems and a break. Instructors and TAs are dedicated to engaging you in the classroom and answering questions in plain language.
- Part 1: Introduction to R and R Studio
- Part 2: Data frames and variable types
- Part 3: Manipulating data frames
- Part 4: Data visualizations and custom functions
Installation Instructions
RStudio is a software commonly used by R practitioners to develop code in R. We will use RStudio to go through the workshop materials, which requires the installation of both the R language and the RStudio software. If you would like to run R on your own computer, complete the following steps prior to the workshop:
-
Download R: Follow the links according to the operating system you are running. You will first need to click on a link corresponding to your operating system, and then an additional link to select a specific version of R. Download the package, and install R onto your computer. You should install the most recent version (at least version 4.1).
- If you are using a Mac, click "Download R for macOS" and then select the right version of R. You will need to select the version corresponding to your specific version of macOS, as well as whether you have an Intel or Apple Silicon Mac.
- If you are using Windows, click "Download R for Windows", then click "base", and click the download link.
- If you are using Linux, click on the link corresponding to your Linux distribution, and then follow the instructions.
-
Download RStudio: Install RStudio Desktop. This should be free. Do this after you have already installed R. The D-Lab strongly recommends an RStudio edition of 2022.02.0+443 "Prairie Trillium" or higher.
- Some individuals with older operating systems may run into odd issues. If you are running into issues with the installation of RStudio, you may need to install a specific version of RStudio. Please check this link if this applies to you.
-
Download these R Fundamentals workshop materials:
- Click the green "Code" button in the top right of the repository information.
- Click "Download Zip".
- Extract this file to a folder on your computer where you can easily access it (we recommend Desktop).
-
Optional: if you're familiar with
git
, you can instead clone this repository by opening a terminal and enteringgit clone [email protected]:dlab-berkeley/R-Fundamentals.git
.
Is R not working on your laptop?
If you do not have R installed and the materials loaded on your workshop by the time it starts, we strongly recommend using the UC Berkeley DataHub to run the materials for these lessons. You can access the DataHub by clicking the following button:
Some users may have to click the link twice if the materials do not load initially.
The DataHub downloads this repository, along with any necessary packages, and allows you to run the materials in an RStudio instance on UC Berkeley's servers. No installation is needed from your end - you only need an internet browser and a CalNet ID to log in. By using the DataHub, you can save your work and come back to it at any time. When you want to return to your saved work, go straight to DataHub, sign in, and click on the R-Fundamentals
folder.
If you don't have a Berkeley CalNet ID, you can still run these lessons in the cloud, by clicking this button:
If you are loading Binder with this repository for the first time, it may take a few minutes to set up. Binder operates similarly to the D-Lab DataHub, but on a different set of servers. By using Binder, however, you cannot save your work.
Run the Code
Now that you have all the required software and materials, you need to run the code.
-
Launch the RStudio software.
-
Use the file navigator to find the R-Fundamentals folder you downloaded from Github. Open
R-Fundamentals.Rproj
by double clicking on the file. -
Open up the file corresponding to the part of the workshop you're attending (
Part1.Rmd
,Part2.Rmd
,Part3.Rmd
,Part4.Rmd
) via the Files panel in RStudio. -
Place your cursor on a given line and press
Command + Enter
(Mac) orControl + Enter
(PC) to run an individual line of code. -
The
solutions
folder contains the solutions to the challenge problems.
Additional Resources
Check out the following online resources to learn more about R:
- Software Carpentry
- Quick-R
- UCLA Institute for Digital Research and Education
- R-bloggers
- R Markdown: The Definitive Guide
- The tidyverse style guide
as well as the following books:
- Bookdown Featured Books
- Introduction to Probability and Statistics in R by G. Jay Kearns.
- Advanced R by Hadley Wickham.
- R for Data Science by Hadley Wickham and Garrett Grolemund.
- R for Everyone by Jared Lander.
- Art of R Programming by Norman Matloff.
About the UC Berkeley D-Lab
D-Lab works with Berkeley faculty, research staff, and students to advance data-intensive social science and humanities research. Our goal at D-Lab is to provide practical training, staff support, resources, and space to enable you to use R for your own research applications. Our services cater to all skill levels and no programming, statistical, or computer science backgrounds are necessary. We offer these services in the form of workshops, one-to-one consulting, and working groups that cover a variety of research topics, digital tools, and programming languages.
Visit the D-Lab homepage to learn more about us. You can view our calendar for upcoming events, learn about how to utilize our consulting and data services, and check out upcoming workshops.
Other D-Lab [Language] Workshops
D-Lab offers a variety of R workshops, catered toward different levels of expertise.
Basic Competency
Intermediate/Advanced Competency
Contributors
Provide a list of contributors here, with links to their webpages (D-Lab or private).