## ```{r info-section, child = system.file("child_documents/info_section.Rmd", package = "tutorial.helpers")} ## ``` ## ```{r download-answers, child = system.file("child_documents/download_answers.Rmd", package = "tutorial.helpers")} ## ``` ## ### Exercise 6 ## ## Explain potential outcomes in about two sentences. ## ## ```{r definitions-6} ## question_text(NULL, ## message = "This is where we place the correct answer. It will appear only after ## students have submitted their own answers. Note that we do not need to wrap the ## answer text by hand.", ## answer(NULL, ## correct = TRUE), ## allow_retry = FALSE, ## incorrect = NULL, ## rows = 6) ## ``` ## ### Exercise 7 ## ## ## ```{r exercise-7} ## question_text(NULL, ## answer(NULL, correct = TRUE), ## allow_retry = TRUE, ## try_again_button = "Edit Answer", ## incorrect = NULL, ## rows = 5) ## ``` ## ## ### ## ## ```{r exercise-7-test} ## ## ``` ## ## ### ## ## median_age <- get_acs(geography = "county", ## variables = "B01002_001", ## year = 2020) ## write_rds(median_age, "data/median_age.rds") ## ## median_age <- read_rds("data/median_age.rds") ## fit_gauss <- brm(formula = biden ~ 1, ## data = poll_data, ## refresh = 0, ## silent = 2, ## seed = 9) ## write_rds(fit_gauss, "data/fit_gauss.rds") ## ## fit_gauss <- read_rds("data/fit_gauss.rds") ## ```{r} ## include_graphics("images/example.png") ## ``` ##
```{r}
## 1 + 1
## ```
##
## > tutorial.helpers::show_file("quarto-1.qmd")
## ---
## title: "Quarto 1"
## author: David Kane
## format: html
## execute:
## echo: false
## ---
## ```{r}
## suppressPackageStartupMessages(library(tidyverse))
## library(palmerpenguins)
## ```
## >
##
## ### Exercise 1
##
## You should be connected to a repo named `r4ds-1`. If you are not, create one and connect to it.
##
## You need two R Terminals: one for running this tutorial and one for your exercises.
##
## Create a new Quarto Document and save it as `analysis.qmd`. Add a YAML header at the top with a title (`"Analyzing the Billboard 100"`) and your name as author.
##
## Render the document by running `quarto render` in the bash Terminal. Open the rendered `analysis.html` file in a new tab by right clicking it in the Explorer and selecting "Open with Live Server". When you run `quarto render` from now on that tab will be updated with the newly rendered file.
##
## Create a `.gitignore` file with `analysis_files` on the first line and then a blank line. Commit and push.
##
## In the R Terminal, run:
##
## ```
## show_file(".gitignore")
## ```
##
## If that fails, it is probably because you have not yet loaded `library(tutorial.helpers)` in the R Terminal.
##
## CP/CR.
##
## ```{r introduction-1}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 3)
## ```
##
## ###
##
##
##
##
## ### Exercise 2
##
## In your QMD, put `library(tidyverse)` in a new code chunk. Render the file by running `quarto render` in the bash Terminal.
##
## Notice that the file does not look good because the code is visible and there are annoying messages. To take care of this, add `#| message: false` to remove all the messages in this setup chunk. Also, add the following to the YAML header to remove all code echoes from the HTML:
##
## ```
## execute:
## echo: false
## ```
##
## Render the file again, using `quarto render`. Only the title and author should appear in the HTML.
##
## In the R Terminal, run:
##
## ```
## show_file("analysis.qmd", chunk = "Last")
## ```
##
## CP/CR.
##
## ```{r introduction-2}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 6)
## ```
##
## ###
##
##
## ### Exercise 3
##
## Place your cursor in the QMD file on the `library(tidyverse)` line. Use `Cmd/Ctrl + Enter` to execute that line.
##
## Note how this command causes `library(tidyverse)` to be copied down to the R Terminal and then executed.
##
## CP/CR.
##
## ```{r introduction-3}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 8)
## ```
##
## ###
##
##
## ### Exercise 4
##
##
##
## Create a `data` directory at the top level of the `XX` repo. This is a good place to store any data that you are working with.
##
## In the bash Terminal, run `ls`.
##
## CP/CR.
##
## ```{r introduction-4}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 5)
## ```
##
## ###
##
## You answer should look something like this:
##
## ```
## $ ls
## README.md analysis.html analysis.qmd analysis_files data
## ```
##
## ###
##
##
## ## XX: First topic (use sentence case)
## ###
##
##
## ### Exercise 1
##
##
##
## We begin by downloading XX directly from GitHub to the `data` directory using `download.file()`.
##
## In the R Terminal, run:
##
## ```
## download.file(
## "https://github.com/PPBDS/ai.tutorials/raw/refs/heads/main/inst/tutorials/r4ds-2/data/cheeses.xlsx",
## destfile = "data/XX"
## )
## ```
##
## CP/CR.
##
## ```{r cheese-1}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 8)
## ```
##
## ###
##
##
## ### Exercise 6
##
## Prompt AI to generate R code that ... Add the code to your QMD in a new chunk. Place your cursor on the first line of the code and run `Cmd/Ctrl + Enter`.
##
## In the R Terminal, run:
##
## ```
## show_file("analysis.qmd", chunk = "Last")
## ```
##
## CP/CR.
##
## ```{r something-1}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 4)
## ```
##
## ###
##
## ```{r}
## # XX: Insert code that produces the correct result — a plot, summary statistics, or printed tibble. With echo = FALSE (the default), students see only the output; add #| echo: true when you want them to study the code too.
## ```
##
## ###
##
##
## ### Exercise 3
##
## Before creating a plot, we need to ensure that your data matches ours. Run your pipe in the R Terminal and compare your output to the result shown below.
##
## In the R Terminal, run:
##
## ```
## show_file("analysis.qmd", chunk = "Last")
## ```
##
## CP/CR.
##
## ```{r xx-first-section-use-sentence-case-3}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 6)
## ```
##
## ###
##
## ```{r xx-first-section-use-sentence-case-3-test}
## # XX: Insert code that prints the tibble students should have at this stage.
## ```
##
## ###
##
##
## ### Exercise 4
##
## Within the latest code chunk, assign the result of the pipe to `x`.
##
## Place your cursor on the line where the pipe is assigned to `x`, run `Cmd/Ctrl + Enter`, thus ensuring that the workspace also includes a copy of `x`.
##
## CP/CR.
##
## ```{r xx-first-section-use-sentence-case-4}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 8)
## ```
##
##
##
## ###
##
##
## ### Exercise 5
##
## Add the option `#| cache: true` to the chunk which creates `x`. This causes Quarto to cache the results of the chunk. The next time you render your QMD, as long as you have not changed the code, Quarto will just load up the saved object.
##
## Run `quarto render` in the bash Terminal. Rendering creates an `analysis_cache` directory next to the QMD.
##
## In the bash Terminal, run `ls`.
##
## CP/CR.
##
## ```{r xx-first-section-use-sentence-case-5}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 5)
## ```
##
## ###
##
##
## ### Exercise 6
##
## Add `analysis_cache` to the `.gitignore`. The contents of the cache directory do not belong on GitHub.
##
## In the R Terminal, run:
##
## ```
## show_file(".gitignore")
## ```
##
## CP/CR.
##
## ```{r xx-first-section-use-sentence-case-6}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 3)
## ```
##
## ###
##
##
## ### Exercise 7
##
## Within the R Terminal, type `x`, which we previously assigned to a pipe and ran in the R Terminal. Hit `Enter`.
##
## CP/CR.
##
## ```{r xx-first-section-use-sentence-case-7}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 8)
## ```
##
## ###
##
## Our result:
##
## ```{r}
## # x
## ```
##
## ###
##
##
## ### Exercise 8
##
## Ask AI to generate R code that uses `x` to plot a basic graph or calculate and present summary statistics showing XX ... Mention you want to use the data from `x`. If using a chat interface copy/paste the `x` you ran in the R Terminal with the resulting tibble. You only need the top 3 lines, mainly to include column names.
##
## Consider adding a title, subtitle, and caption. If axis labels would be useful, add them, but if unnecessary, don't bother. Don't assign the code for the plot to any variable. Put the plot code in a new code chunk. Run `quarto render` to ensure that everything works. Make your plot look nice.
##
## In the R Terminal, run:
##
## ```
## show_file("analysis.qmd", chunk = "Last")
## ```
##
## CP/CR.
##
## ```{r xx-first-section-use-sentence-case-8}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 12)
## ```
##
## ###
##
## Our result:
##
## ```{r}
## # XX: Insert plotting code. With echo = FALSE (the default), students see only the plot, not this code. Make sure the plot has a subtitle that states the take-away message and uses clean, concise code.
## ```
##
## ###
##
##
## ## Summary
## ###
##
##
## ### Exercise 1
##
## Run `quarto render` to ensure that everything works. The resulting HTML page should be attractive, showing clean versions of your plot(s).
##
## At the R Terminal, run:
##
## ```
## show_file("analysis.qmd")
## ```
##
## CP/CR.
##
## ```{r summary-1}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 30)
## ```
##
## ###
##
##
## ### Exercise 2
##
## Publish your rendered QMD to GitHub Pages. In the bash Terminal --- not the R Terminal! --- run:
##
## ```
## quarto publish gh-pages analysis.qmd
## ```
##
## Copy/paste the resulting URL below.
##
## ```{r summary-2}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 1)
## ```
##
## ###
##
##
##
## ### Exercise 3
##
## Commit and push all your files. Copy/paste the URL to your Github repo.
##
## ```{r summary-3}
## question_text(NULL,
## answer(NULL, correct = TRUE),
## allow_retry = TRUE,
## try_again_button = "Edit Answer",
## incorrect = NULL,
## rows = 3)
## ```
##
## ###
##
##