---
title: "My first Quarto document"
format:
  html:
    toc: true
    toc-depth: 1
    embed-resources: true
---

# Intro


**Macalester College** is in the *Twin Cities*.
It has:

- four seasons
- bagpipes
- delightful students

Check it out for yourself:

![](https://www.macalester.edu/about/wp-content/uploads/sites/191/2019/12/campusmap336.png)



\
\




# Exercise 1: Deduce Quarto features

Check out the appearance and contents of this document. Thoughts?

In the toolbar at the top of this document, click the **Render** button with the blue arrow to render this .qmd file into a .html file.

- You will see status messages appear in the "Background Jobs" pane near the Console.
- A webpage will popup in RSTudio's Viewer pane, displaying the rendered HTML file. (It may also display in your browser at `http://localhost:####/`.)

Toggling between this .qmd and the rendered HTML, explain the purpose of the following features in the .qmd file:

`*`

`**`

`#`

`-`

`\`

`![](url)`

Also check to see in the Files pane of RStudio or in your File Explorer/Finder that you see a file called `quarto-demo.html` in the same folder as `quarto-demo.qmd`.

- This is the same as what popped up in your web browser but is a saved file that can be shared/uploaded.
- When you render .html files for assignments, you will submit this .html on Moodle.






\
\
\




# Exercise 2: Code


How does the following line of code appear in the .qmd? The .html? So...?!

seq(from = 100, to = 1000, by = 50)









\
\
\



# Exercise 3: Chunks

Quarto isn't a mind reader -- we must distinguish R code from text.
We do so by putting code inside an **R code chunk**:

```{r}

```

- Put the `seq()` code in the chunk.
- Press the green arrow in the top right of the chunk. What happens in the qmd?
- Render. What appears in the html: R code, output, or both?

\

**Hot tip:** You can use a keyboard shortcut to insert a code chunk!

- Ctrl + Alt + I (Windows and Linux)
- Command + Option + I (Mac)



\
\
\




# Exercise 4: Practice

- Use R code to create the following sequence: 10 10 10 10
- Store the sequence as `four_tens`.
- Use an R function (which we haven't learned!) to add up the numbers in `four_tens`.





\
\
\




# Exercise 5: Fix this code

Code is a form of communication, and the code below doesn't cut it.

Put the code in a chunk and fix it.

Rep(x = 1, times = 10)
seq(from=100,to=1000,length=20)
theNumberofStudentsinthisclass<-27



\
\
\


# Exercise 6: Comments

Run the chunk below.
Notice that R ignores anything in a line starting with a pound sign (`#`).
If we took the `#` away we'd get an error!

```{r}
# This is a comment
4 + 5
```

We'll use this feature to **comment our code**, i.e. leave short notes about what our code is doing.
Below, replace the `???` with an appropriate comment.

```{r}
# ???
temperature_c <- 10
temperature_f <- temperature_c * 9/5 + 32
temperature_f
```


# Wrapping up

When you're done:

- Close the `http://localhost:####/` tab in your browser
- Open up the Console pane in RStudio, and click the Background Jobs tab.
- Click the Stop button in the top right of the Background Jobs pane to end the rendering process.

Use these steps whenever you're done working with a .qmd file and rendering it to an .html file.


# Bonus: keyboard shortcuts

Some things can be awkward to type, and sometimes using the mouse to click on things can be slow. Putting in the effort to learn a few keyboard shortcuts will make your RSTudio experience a lot better.

You can see and modify shortcuts from the Tools menu in (unsurpsingly) "Modify Keyboard Shortcuts".

- In the console, some people find that typing `<-` is a bit awkward. Maybe there's an easier way?
- In the Modify Keyboard Shortcuts dialog, search for "assign".
- What's the shortcut to insert an assignment operator? Try it below to assign a value to `my_variable`.
- Want to change that? Click on the shortcut and type the new one you want.

```{r}
# 1. Uncomment the line with 'my_variable'.
# 2. Use a shortcut so that my_variable is assigned some numeric value.

# my_variable

# Now tell R to print out the value of my_variable and confirm that it
# got assigned the value above. What command does that?

```

Another thing you will do frequently is run the R code in a code chunk. You can click the green arrow, but it's often faster to use a shortcut.

- Maybe there's a shortcut?
- Search for "chunk" and scroll around to find something to execute the current chunk.
- Try the shortcut in the chunk above!
