[1] "Hello!"
Topics: Course Logistics, R, Markdown
Role | Name | Office Hours | |
---|---|---|---|
Instructor | Sabrina Nardin | nardin@uchicago.edu | Tue & Thu, 2:30–3:30 PM (after class) |
Teaching Assistant | Zach Meyer | zmeyer@uchicago.edu | Tue 2:30–3:30 PM (after class) |
How to Reach Out
The goal of this course is to acquire basic computational skills. Specifically:
You won’t become an R expert in a few weeks, BUT you will:
learn the basics and gain confidence to explore new techniques beyond this course
use R as a tool for analyzing social science data
Main topics of this course:
We start simple and build toward more complex code
We use a mix of lectures, in-class activities, assignments (take-home and in-class), and we rely on several platforms (e.g., course website, Canvas, Ed Discussion, Workbench, Git/GitHub, and Markdown).
All course materials are free and accessible from our website.
See “Assessment” from our Syllabus and the Course Schedule:
In this course we use RStudio Workbench, which is cloud-based version of RStudio that runs in your browser.
Next lecture we will learn the basics of Git and GitHub and complete the Software Setup for the course.
Check our website under “Software Setup” for details.
In groups of 3-5 people, please share:
Done early?
If your group finishes early, please complete this short survey if you haven’t already. It only takes a minute and helps us better understand your background and what you’re hoping to learn in this course.
Attend classes and bring a laptop (no cell phones)
Review in-class materials and complete assigned work
Ask questions and collaborate
Researchers collaborate on projects. Developers work in teams to write programs. AI is becoming part of our daily and academic lives.
→ Collaboration is good and encouraged, but in this course you are also expected to:
Tool | What It Is |
---|---|
R | A programming language for data analysis, statistics, and visualization. |
RStudio | A user-friendly interface (IDE) for using R. |
Workbench | A cloud-based version of R/RStudio with everything pre-installed. We will use it in this course to minimize setup issues. |
Workbench: https://macss-r.uchicago.edu/
Today we learn how to:
We learn all of this via a live coding activity:
R Markdown is a file format (with extension .Rmd
) that combines R code, using code chunks, and text in a single document. It’s very popular because it makes it easy to create reproducible reports, analyses, and presentations.
You might hear about Quarto (with extension .qmd
), which is a newer alternative to R Markdown. We won’t cover Quarto in this course, but if you learn R Markdown, you can quickly adjust to Quarto.
File Type | Extension | Key Differences |
---|---|---|
R Script | .R |
Supports code |
R Markdown | .Rmd |
Supports code and formatted text |
Markdown | .md |
Supports formatted text |
We use all three, but mainly .Rmd
for assignments and .md
for Git/GitHub documentation.
YAML header for document title, author, output format, etc. Insert it at the top between ---
Text regular Markdown for headers, lists, links, etc.
Code chunks for code. Insert it with triple backticks ```
Code Chunk Tips
Three ways to insert a code chunk in your R Markdown:
```{r}
and ```
This is what we type (YAML, text, code):
The YAML header sits at the top of your .Rmd
and tells R what the document is about and how to display it (e.g., as a html, PDF, Word, etc.). Spacing, indentation, and ---
all matters!
The example below shows three fields but many more can be added:
#
starts a COMMENT in R Scripts and R Markdown Code Chunks#
for code explanations or debugging, space doesn’t matterElement | Syntax Example | Notes | Preview |
---|---|---|---|
Link | [RStudio](https://www.rstudio.com/) |
Text in [] , URL in () |
Link |
Image |  |
Start with ! , include optional "title" |
Image |
Table | | Tool | Use | |---------|---------| | R | Stats | |
Use | for columns and --- for header |
Table |
Note:
Option | What it does | Default |
---|---|---|
eval = FALSE |
Code is not run, only shown; results do not appear. Useful for code examples or showing code with errors. | eval = TRUE |
include = FALSE |
Code is run, but both code and results are hidden. Useful for setup code you don’t want to display. | include = TRUE |
echo = FALSE |
Code is run, results are shown, but code is hidden. Good when readers only need the output. | echo = TRUE |
error = TRUE |
Code is run and shown, even if it throws an error. Useful when demonstrating broken code. | error = FALSE |
message = FALSE / warning = FALSE |
Code is run, but messages and warnings are hidden from the output. | message = TRUE / warning = TRUE |
Check this table and options for more.
R Markdown lets you create documents that combine text, code, and output, and “render” or “knit” them in formats like html, pdf, word, and more.
Rendering Tips
Three ways to render your R Markdown document:
Click “Knit” in RStudio and choose an output
Set the format in the YAML header such as html_document
,word_document
, pdf_document
, github_document
, etc.
Use render()
in your console by typing rmarkdown::render("my-document.Rmd", output_format: html_document
). More info here
When you “knit” your document, the following sequential things happen:
R Markdown sends the .Rmd
file to knitr
http://yihui.name/knitr/
Knitr executes all of the code chunks and creates a new plain Markdown .md
file which includes the code and its output
This plain Markdown file is then converted by pandoc
into any number of output types including html, PDF, Word document, etc.: http://pandoc.org/
Click on the icon bottom-right corner > Tools > PDF Export Mode > Print as a Pdf