Practice 1: R Basics, Organization, and Quarto

Let’s work through what you saw in Week 1 together. Rather than treating this as a separate assignment, think of it as picking up where the lessons left off: we’ll walk through the same ideas step by step, and you’ll try each one out for yourself.

Due Sunday, 10/04 at 11pm.

Week 1 covered six lessons:

Lesson Topic Video Slides What you’ll practice here
1 Welcome Video Slides Getting set up
2 Course logistics Video Slides Getting set up
3 Download + Intro to R & RStudio Video Slides Getting set up
4 Basics Video Slides R as a calculator, relational operators
5 Folder and file organization Video Slides Organizing your files and folders
6 Quarto and .qmd’s Video Slides Quarto questions and your own .qmd
TipHow this works

There are two kinds of questions on this page:

  • Code questions have a little R sandbox you can type directly into. Click Run Code to try your answer. A green box means you’ve got it; any other color means it’s not quite right yet, and the message will try to nudge you toward the fix. If you get stuck, click Show Hint. If you want a clean slate, click Start Over. If you want to see how a nicely formatted version would look, click Format.
  • Multiple choice and short answer questions are for answers that are words, not code. Pick an option (or type your answer and click Check my answer) and you’ll get feedback right away. Open the Hint box under a question if you get stuck.

Your answers to both kinds are saved as you go, so you can leave and come back.

Turning it in: at the end of this page, click Download my answers as .qmd. That file is a real Quarto document, and the last section walks you through editing and rendering it in RStudio, which is your practice for Lesson 6. You’ll submit both the .qmd and the rendered .html on Brightspace. Before you download, fill in the AI Use Statement (even if you didn’t use AI).

Getting set up

These come from Lessons 1–3. Most of them happen outside this page, so check each box once you’ve done it.

Setup checklist (ungraded self-check)

If anything goes wrong with installing, post on Slack or message me right away and we’ll troubleshoot together. If you have learning accommodations, email me so we can talk about how they’ll work in our class.

  1. In RStudio, which pane shows you the output of your code after you run it?

Look at the RStudio interface slide in Lesson 3. One pane is for writing code, one shows output, one lists objects, and one shows plots and help pages.

Warming up: R as a calculator

Recall from Lesson 4 that R can be used just like a calculator, and it follows the same order of operations (PEMDAS) you already know:

1 / 200 * 30
(59 + 73 + 2) / 3
sin(pi / 2)

Also recall the operators from that lesson:

Operation Written In R
Addition \(1+1\) 1+1
Subtraction \(2-1\) 2-1
Multiplication \(3\times 2\) or \(3\cdot 2\) 3*2
Division \(3 / 2\) or \(\dfrac{3}{2}\) 3/2
Exponential \(4^2\) 4^2
Square root \(\sqrt{4}\) or \(4^{1/2}\) 4^(1/2) or sqrt(4)

Let’s put these to use. Give each of the following a try:

  1. Calculate \(\dfrac{(15 + 9)^2}{3}\).
NoteHint 1

Remember R follows the usual order of operations. Parentheses () are evaluated first, and ^ is used for exponents.

NoteHint 2

Start by adding 15 + 9 inside parentheses, then square the result with ^2, then divide by 3.

  1. Calculate \(100 - (4 \times 15) + 2^3\).
NoteHint

Work out the multiplication inside the parentheses first (4 * 15), then the exponent (2^3), then add and subtract left to right.

  1. Calculate \((60 \div 4) + (9 - 2)^2\).
NoteHint

Work out the division inside the first parentheses (60 / 4), then the subtraction and exponent in the second ((9 - 2)^2), then add the two results together.

  1. A public health researcher recorded blood pressure readings (in mmHg) from three patients: 118, 132, and 126. Calculate their average blood pressure by adding the three readings and dividing by the number of patients.
NoteHint 1

An average is the total divided by how many values there are. Which step has to happen first?

NoteHint 2

Wrap the sum in parentheses so it happens before the division: (118 + 132 + 126) / 3.

  1. Calculate the square root of 144.
NoteHint

The operator table above shows two ways to take a square root: sqrt(), or raising to the power of (1/2). Either works!

Relational operators

Lesson 4 also introduced relational operators. Instead of computing a number, these operators ask R a yes/no question, and R answers with TRUE or FALSE:

Operation In R
Less than 1<1
Greater than 1>1
Less than or equal to 1<=1
Greater than or equal to 1>=1
Equal to 1==1
Not equal to 1!=1

Notice that “equal to” is two equals signs (==), not a single =. Let’s practice asking R some questions:

  1. Is 7 times 8 greater than or equal to 60?
NoteHint

“Greater than or equal to” is written >= in R. Multiply first, then compare.

  1. Is 100 divided by 4 equal to 25?
NoteHint

“Equal to” is written == (two equals signs) in R, not a single =.

  1. Is 17 not equal to 17?
NoteHint

“Not equal to” is written != in R.

  1. Is 3 squared less than or equal to 8?
NoteHint

“Less than or equal to” is written <= in R. Square 3 first with ^2, then compare to 8.

  1. Is the sum of 5 and 3 greater than the product of 4 and 2?
NoteHint

Put each side in its own parentheses: the sum (5 + 3) and the product (4 * 2), then compare them with >.

Putting it together: weekly flu case counts

Now let’s combine arithmetic and relational operators on some real-looking data.

A county health department reports the following weekly flu case counts over 4 weeks: 42, 67, 55, and 38.

You’ll notice you have to retype these four numbers in every question. That gets old fast! In Lesson 14 (Objects), you’ll learn how to save the numbers once and reuse them.

  1. Calculate the total number of flu cases across all 4 weeks.
NoteHint

Add the four weekly counts together with +.

  1. Find the average weekly case count.
NoteHint

Same idea as the blood pressure question: put the sum in parentheses, then divide by the number of weeks.

  1. The county sends out a flu alert when the average weekly case count is greater than 55. Write one line of code that asks R whether the county should send an alert.
NoteHint

Take your average from the last question (parentheses and all), and compare it to 55 using >.

Organizing your files and folders

Recall from Lesson 5 the naming conventions for files and folders:

  • Keep names short, relevant, and lowercase
  • Use underscores to separate parts of a name — never spaces (some people use hyphens - between words and underscores _ between sections; just be consistent)
  • Add a leading number (like 01_, 02_) when files should be read or run in a particular order
  • Use YYYY-MM-DD for any dates in a file name, so alphabetical sorting matches chronological order
  1. A classmate is deciding between three names for the first script in their analysis. Which one follows the conventions from Lesson 5?

Look for the name that is lowercase, uses underscores instead of spaces, and starts with a number showing where it falls in the workflow.

  1. Someone saved a report as Flu Report 3-15-2026.pdf. Rename it so it follows all of Lesson 5’s rules, with the date in YYYY-MM-DD format. Type the new file name (no quotes needed) and click Check my answer.

Fix three things: make it lowercase, swap the spaces for underscores, and rewrite the date so the year comes first. March 15, 2026 in YYYY-MM-DD format is 2026-03-15 (notice the leading zero on the month!).

  1. In our class folder, which subfolder of data_project holds the original data that you should never modify?

data_project has two subfolders. One is for the data as you received it, and the other is for data you’ve cleaned up.

  1. This one isn’t something this page can check for you. On your own computer, create your course folder with the structure from Lesson 5. You’ll use this same folder for the rest of the course, and you’ll save this practice into it at the end of the page.

Ungraded self-check. Put the folder somewhere that makes sense (Documents, OneDrive, etc.) and name it PUBH_523_26F or PUBH_623_26F, whichever course you’re in:

PUBH_523_26F
├── admin
├── data_lessons
├── data_practice
├── data_project
│   ├── data_raw
│   └── data_processed
├── lessons
├── practice
└── project
  • Make data_raw and data_processed inside data_project.

  • Check that folder names use underscores and no spaces.

  • Make sure there are no slashes (/) in your folder names! The lesson video shows a / after each folder name, but that’s only there to mark it as a folder.

Quarto and .qmd files

Lesson 6 covered the three types of content in a .qmd file:

  1. YAML metadata — settings between --- lines at the very top (title, author, output format)
  2. Text — written in Markdown (headings with #, bold with **, bullet lists with -)
  3. Code chunks — executable R code between ```{r} and ```

It also covered chunk options, which go at the top of a chunk after #| and control what shows up when you render:

Chunk option What it does
echo: false Hides the code, but still shows the result
warning: false Hides warning messages
include: false Runs the code, but hides both code and output
eval: false Doesn’t run the code at all (no output)
  1. True or false: the YAML header of a .qmd file goes between two lines that each just say ---.

Think back to the “Hello, Penguins” example in Lesson 6. What sits at the very top of the file?

  1. Look at this line from a .qmd file:

    ## Meet the penguins

    Which of the three types of content is it?

It’s not between --- lines, and it’s not inside ```{r}. The ## is Markdown for a heading.

  1. Suppose you want a code chunk to show its result but hide the code, and you also want to hide any warnings it produces. Which chunk options would you add? Select all that apply, then click Check my answer.

You need two options: one that hides the code (but keeps the result), and one that hides warnings. Check the chunk option table above.

  1. You have a chunk with code that you know has an error, but you still want the rest of your document to render. Which chunk option would you add?

A chunk with an error stops the whole render. Which option tells Quarto to skip running the code entirely?

AI Use Statement

NoteAI Use Statement

Using AI is not required in this class. If you did use an AI tool (ChatGPT, Claude, Copilot, Gemini, an RStudio assistant, etc.) on this practice, add a brief AI Use Statement. Include:

  • Which tool(s) you used
  • What for (a sentence or two, with question numbers)
  • Where it contributed to any written answers (if at all)
  • You do NOT need to link your conversation.

For example:

AI Use Statement: Claude was used to explain an error message in Question 3. All reasoning and answers are my own.

OR

AI Use Statement: AI was not used in this assignment.

Before using AI, check the table of allowed uses in the Generative AI Policy. For practice, AI can help you understand (explain an error or a concept, explain what a function does, check an answer you already worked out), but it should not do the problem for you. A half-finished answer that shows your thinking is always better than a polished one from AI!

Fill in your statement below. It’s saved as you type, and it goes at the top of your downloaded .qmd, right where your submission needs it.

Your turn: working in a real .qmd

Quarto makes the most sense when you use it yourself, so this last part happens in RStudio. The Download my answers as .qmd button below gives you a Quarto file with all your answers from this page (code answers go in R chunks, and multiple choice and short answers go in as text), plus a few spots set up for you to practice each piece of Lesson 6. Work through the steps in order, and check each box as you go.

TipKeep the Lesson 6 slides open

Every step below matches a slide in Lesson 6. If you get stuck, the Quarto cheatsheet and Slack are good places to look.

  1. Complete each step in your downloaded .qmd.

Step A: Download and file it (Lesson 5 practice!)

  1. Answer as many questions above as you can, then click Download my answers as .qmd at the bottom of this page.
  2. Move the file from your Downloads folder into PUBH_523_26F/practice/ (or PUBH_623_26F/practice/).
  3. Rename it to lastname_firstinitial_practice_01.qmd using your own name, for example wakim_n_practice_01.qmd. No spaces!
  4. Open RStudio, then open the file with File → Open File… (double-clicking may open it in a different program).

Step B: Your first render (it will fail on purpose!)

Find the ## Chunk options: eval section. That chunk has a mistake on purpose, so you can see what a failed render looks like and how to rescue it: it asks for the square root of "144" in quotes, which is text, not a number.

  1. Click Render (or Cmd + Shift + K on Mac / Ctrl + Shift + K on PC). It will stop with an error. That’s expected! Look at the Background Jobs or Render tab: R tells you which chunk broke and prints the message non-numeric argument to mathematical function.
  2. Add #| eval: false to the top of that chunk and render again. It should work now, and the HTML opens in a new window.
  3. If the render stops at one of your answers instead, fix that answer or add #| eval: false to that chunk too.

(You’ll learn more about reading error messages in Lesson 9.)

Step C: Edit the YAML

At the very top, between the --- lines, you’ll see:

author: "Your name here"

Replace Your name here with your name, keeping the quotes. Then Render again and check that your name and today’s date show up at the top of the HTML.

Optional exploration: change toc: true to toc: false, render again, and see what disappears. Then change it back.

Step D: Write some text with Markdown

Find the ## About me section near the bottom of the file. Under it, add:

  • A level 3 heading (### ...) with a title of your choice
  • 2–3 sentences about yourself or what you hope to learn in this class, with at least one word in bold (**bold**) and one in italics (*italics*)
  • A bulleted list with at least two items (start each line with -)

You can type the Markdown yourself in the Source editor, or switch to the Visual editor (top left of the editor window) for a Word-like toolbar. If you use Visual, switch back to Source afterward to see what Markdown it wrote for you.

Step E: Hide code with echo: false

Find the ## Chunk options: echo and warning section. It has a chunk that calculates the average flu count. Add these two lines at the very top of the chunk, right after ```{r}:

#| echo: false
#| warning: false

Render, and check that the result (50.5) shows but the code doesn’t.

Step F: Insert your own code chunk

Find the ## My own code chunk section. Insert a brand new R chunk under it using any of the three ways from Lesson 6:

  • Click the green +C button at the top of the editor
  • Cmd + Option + I (Mac) / Ctrl + Alt + I (PC)
  • Type ```{r} on one line and ``` a few lines below

Inside the chunk, write any calculation or comparison you like from this practice (for example, 3^2 <= 8). Render and check that your code and its result both show up.

Step G: Render and submit

  1. Render one last time. You should now see both lastname_firstinitial_practice_01.qmd and lastname_firstinitial_practice_01.html in your practice/ folder.
  2. Open the .html in your browser and look it over. Make sure your AI Use Statement shows up at the top. If it says “Not filled in yet,” edit that line in your .qmd and render again.
  3. Upload both files to the Practice 1 assignment on Brightspace.

NoteDidn’t finish every question?

That’s okay! Practice is graded on completion (at least 75% of the question parts). Any code question you left blank gets #| eval: false in your downloaded file, so it won’t stop your render, and any multiple choice or short answer question you skipped shows up as “Not answered yet.”


Check your overall progress on this practice set on the My Progress page.