library(learnr) library(tutorial.helpers) library(knitr) library(tidyverse) library(palmerpenguins) knitr::opts_chunk$set(echo = FALSE) knitr::opts_chunk$set(out.width = '90%') options(tutorial.exercise.timelimit = 60, tutorial.storage = "local")
This tutorial covers more details in the usage of Git and GitHub. Some material is from R for Data Science (2e) by Hadley Wickham, Mine Çetinkaya-Rundel, and Garrett Grolemund.
The most useful reference for Git/GitHub is Happy Git and GitHub for the useR. Refer to that book whenever you have a problem.
This first project will simply review the steps which we have already learned. Making the data science work cycle second nature requires practice.
We don't need to set up Git and Github again, having already done so above. In this project, our goal is to publish a nice graphic of data about penguins.
Create a Github repo (called project-1
). Make sure to click the "Add a README file" check box. Copy/paste the URL for its Github location.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3)
https://github.com/davidkane9/project-1
As a reminder, we often provide our answer to a question right after asking you for your answer, as we do above. In many cases, our anwer will be different because, as here, we have a different user name on GitHub.
Always start a new data science project with a new Github repo.
Connect the project-1
Github repo to a project on your computer. Recall the steps:
File -> New Folder from Git ...
Paste the repo URL (ending in .git
) into the "Git repository URL" box.
Check "Open in new window" box.
Click "OK"
From the Console in the new Positron window, run list.files()
. (You might need to select R for the interpreter first.) CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3)
> list.files() [1] "README.md" >
The default README has an "md" suffix to indicate that it is a Markdown document.
Positron has automatically placed you within the project-1
project. The project-1
directory should be in the location in which you store your all your projects.
Go to File -> New File ...-> Quarto Document
. Title it "Quarto 1". You are the author. Save it with the name quarto-1.qmd
.
From the Console, run list.files()
. CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 6)
Your answer should look like this:
> list.files() [1] "quarto-1.qmd" "README.md" >
Titles should be in title case, obviously. File names are usually all lower case. Spaces in titles are fine, but there should never be spaces (or other weird characters --- other than underlines, _
, and, less commonly, dashes -
) in file names.
Click the “Preview” button or, better, press Cmd/Ctrl + Shift + K
.
This will create an HTML file and display it in the Viewer tab in the Secondary Activity Bar.
Look at the Terminal. Copy-and-paste the lines which resulted from rendering quarto-1.qmd
.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 10)
dkane@macbook project-1 % quarto preview /Users/dkane/Desktop/projects/project-1/quarto-1.qmd --no-bro wser --no-watch-inputs pandoc to: html output-file: quarto-1.html standalone: true section-divs: true html-math-method: mathjax wrap: none default-image-extension: png metadata document-css: false link-citations: true date-format: long lang: en title: Quarto 1 author: David Kane Output created: quarto-1.html Watching files for changes Browse at http://localhost:4817/
Clicking the "Preview" button runs, behind the scenes on the Terminal, the quarto preview
command. This command does two things. First, it "renders" quarto.qmd
, taking this QMD file as input and producing quarto-1.html
as output. Second, it "watches" the HTML file. If something changes in that file --- because we have edited quarto.qmd
and then rendered it --- Positron will show the new HTML in the Viewer atb.
The pandoc
and metadata
portions of the previous output give more details on the process. Positron itself is not doing the main work. That is Quarto's job. Instead, Positron is managing Quarto and other processes.
At the Terminal, use Ctrl-C
to stop the watching process. Then, run ls
. CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3)
Watching files for changes Browse at http://localhost:4817/ ^C% dkane@macbook project-1 % ls README.md quarto-1.html quarto-1.qmd quarto-1_files dkane@macbook project-1 %
Note that ^C
symbol, which is how Ctrl-C
is recorded.
The quarto-1.html
is our rendered file, as expected. The quarto-1_files
directory contains a variety of files which were involved in the transformation of quarto-1.qmd
into quarto-1.html
. None of the files in quarto-1_files
are worth understanding, at least at this point in your data science education.
Create a .gitignore
file with two lines: quarto-1_files
and a blank line. Save the file. Make sure to save it at the top of the project, not inside of the quarto-1_files
directory.
In the Terminal, run cat .gitignore
. CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3)
dkane@macbook project-1 % cat .gitignore quarto-1_files dkane@macbook project-1 %
Every time that you render a Quarto document, Quarto creates a directory in which it places the supporting files which we used in that rendering. The name of that directory is name-of-your-file-without-the-suffx
plus _files
. The material in this directory is not worth backing up on GitHub. They are neither the original source material (quarto-1.qmd
) which we will edit to make changes nor the final product (quarto-1.html
) which we will show to others.
However, we need to ensure that the HTML file looks how we want it to look when we publish it on the web.
Press the Source Control button. Commit all the files --- .gitignore
, quarto-1.qmd
and quarto-1.html
--- which have not been committed yet. Your commit message should be something like "Initial version." Sync all the files.
From the Terminal, run git log
. CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 8)
dkane@macbook project-1 % git log commit 71e6d06fd555096d79719e267412d51856a0e515 (HEAD -> main, origin/main, origin/HEAD) Author: David Kane <dave.kane@gmail.com> Date: Fri Mar 14 15:20:50 2025 -0400 initial version commit 6fcbf60866ba728132c94f0c0496f3770006fd42 Author: David Kane <dave.kane@gmail.com> Date: Fri Mar 14 13:18:01 2025 -0400 Initial commit dkane@macbook project-1 %
You should see your commit message in the top (most recent) commit.
Add a code chunk within your document which includes library(tidyverse)
. Render the document to ensure that everything works. (Fix any errors if it doesn't.)
In the Console, run:
tutorial.helpers::show_file("quarto-1.qmd", chunk = "Last")
CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3)
> tutorial.helpers::show_file("quarto-1.qmd", chunk = "Last") library(tidyverse) >
Anytime you use show_file()
without having a blank line at the end of the file, you will get a warning message.
Recall that you can add a code chunk by either pressing the “Insert” button icon in the editor toolbar (the green button with the letter C and a tiny plus sign) or by using the shortcut key combination: Command + Option + i
or Ctrl + Alt + i
.
You could also manually type the chunk delimiters ```r
and ```
, but, obviously, that is the worst option.
Add library(palmerpenguins)
to the code chunk. Render the document to ensure that everything works. (Fix any errors if it doesn't.)
In the Console, run:
tutorial.helpers::show_file("quarto-1.qmd", chunk = "Last")
CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 8)
Your answer should look like:
> tutorial.helpers::show_file("quarto-1.qmd", chunk = "Last") ```r library(tidyverse) library(palmerpenguins) ```
When you render the document, Quarto sends the QMD file to knitr, which executes all of the code chunks and creates a new Markdown (.md
) document which includes the code and its output. The Markdown file generated by knitr is then processed by pandoc, which is responsible for creating the finished HTML file.
Add a new code chunk, which just includes penguins
. Render the document. Copy the displayed bottom contents of quarto-1.html
below, starting with penguins
.
We often ask you to "copy" from the HTML. It is OK if what you copy looks ugly, has lost its formatting and so on. We just want to make sure that your HTML includes, more or less, the information that it should.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 15)
Your HTML should look like this. Of course, your copy/paste job will be a mess.
include_graphics("images/penguins.png")
Because the code is just the name of the tibble, R prints out the first 10 rows of the tibble, along with some other information, just like it would if you typed penguins
at the Console.
We don't want our R code to be echoed in the HTML. So, to the YAML header, add:
execute: echo: false
Also, we don't want those warnings from loading the tidyverse package to be included in the HTML, so add #| warning: false
to the first code chunk. Cmd/Ctrl + Shift + K
to confirm that everything looks good. The only thing that should appear in the HTML, other than title and author, is the penguins
data set.
In the Console, run tutorial.helpers::show_file("quarto-1.qmd")
. CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 12)
> tutorial.helpers::show_file("quarto-1.qmd") --- title: "Quarto 1" author: David Kane format: html execute: echo: false --- ```r #| warning: false library(tidyverse) library(palmerpenguins) ``` ```r penguins ``` >
Ask your favorite AI to create a beautiful graphic using the penguins
data. Phrase the question however you like. I asked chattGPT:
Using R and the tidyverse package, create a beautiful graphic using the penguins data from the palmerpenguins package.
Replace penguins
in the second code chunk with the graphics code generated by the AI. (I had to make three changes in the code I got in order to get rid of some annoying messages and warnings. I could also have just asked the AI to do so for me.) My graphic:
theme_custom <- theme_minimal(base_size = 14) + theme( plot.title = element_text(face = "bold", size = 16, hjust = 0.5), plot.subtitle = element_text(size = 12, hjust = 0.5), legend.position = "right", panel.grid.major = element_line(color = "grey80"), panel.grid.minor = element_blank() ) # Plot: Flipper Length vs Body Mass penguins |> drop_na() |> ggplot(aes(x = flipper_length_mm, y = body_mass_g, color = species)) + geom_point(alpha = 0.8, size = 3) + geom_smooth(method = "lm", formula = y ~ x, se = FALSE, linetype = "dashed") + scale_color_brewer(palette = "Dark2") + labs( title = "Penguin Flipper Length vs Body Mass", subtitle = "Species comparison from Palmer Station, Antarctica", x = "Flipper Length (mm)", y = "Body Mass (g)", color = "Species", caption = "Data from the palmerpenguins package" ) + theme_custom
Render quarto-1.qmd
, either by hitting the "Preview" button or by using Cmd/Ctrl + Shift + K
.
From the Console, run tutorial.helpers::show_file("quarto-1.qmd", chunk = "Last")
. CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3)
> tutorial.helpers::show_file("quarto-1.qmd", chunk = "Last") # Basic clean theme theme_custom <- theme_minimal(base_size = 14) + theme( plot.title = element_text(face = "bold", size = 16, hjust = 0.5), plot.subtitle = element_text(size = 12, hjust = 0.5), legend.position = "right", panel.grid.major = element_line(color = "grey80"), panel.grid.minor = element_blank() ) # Plot: Flipper Length vs Body Mass penguins |> drop_na() |> ggplot(aes(x = flipper_length_mm, y = body_mass_g, color = species)) + geom_point(alpha = 0.8, size = 3) + geom_smooth(method = "lm", formula = y ~ x, se = FALSE, linetype = "dashed") + scale_color_brewer(palette = "Dark2") + labs( title = "Penguin Flipper Length vs Body Mass", subtitle = "Species comparison from Palmer Station, Antarctica", x = "Flipper Length (mm)", y = "Body Mass (g)", color = "Species", caption = "Data from the palmerpenguins package" ) + theme_custom >
Generative AI is the biggest change in the day-to-day work of data scientists in the last 30 years. Use it every chance you get.
Our plot looks nice! Let's share it with the world!
From the Terminal, run quarto publish gh-pages quarto-1.qmd
. CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 20)
That command generates a lot of text. Let me highlight some key parts:
dkane@macbook project-1 % quarto publish gh-pages quarto-1.qmd ? Publish site to https://davidkane9.github.io/project-1/ using gh-pages? (Y/n) › Yes
The first time you publish, Quarto will confirm the location, which is just the standard GitHub Pages address, using your user name and the repo name.
Saved working directory and index state WIP on main: 71e6d06 initial version Switched to a new branch 'gh-pages' [gh-pages (root-commit) b8263f3] Initializing gh-pages branch remote: remote: Create a pull request for 'gh-pages' on GitHub by visiting: remote: https://github.com/davidkane9/project-1/pull/new/gh-pages remote: To https://github.com/davidkane9/project-1.git * [new branch] HEAD -> gh-pages ```` Quarto interacts with your GitHub repo directly, creating a new branch, `gh-pages`, which will be used to construct the website.
[✓] Deploying gh-pages branch to website (this may take a few minutes) [✓] Published to https://davidkane9.github.io/project-1/
dkane@macbook project-1 %
Quarto keeps you informed as it completes the work. <!-- DK: Could add some screen shots from GitHub Pages site to help understand what is going on. --> ### Exercise 14 Commit and sync all the files in the project. Report the URL for the new webpage. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### Your URL should look like this:
https://davidkane9.github.io/project-1/
Note that the name of the file, `quarto-1.html`, plays no part in the URL. We told Quarto that we wanted a website with just one page, not a collection of pages. So, it could simplify by making `quarto-1.html` the default page for the `project-1` directory. <!-- DK: Not sure this explanation is correct. --> ## Project 2 ### With `project-1`, we went through all the steps of a data science project: start with GitHub repo; connect to project on local computer; use a Quarto document for analysis; publish to GitHub Pages; push final changes to the repo. Restart the R session with `Cmd/Ctrl + Shift + 0`. ### Exercise 1 Create a Github repo called `project-2`. Make sure to click the "Add a README file" check box. Copy/paste the URL for its Github location. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### Your answer should look something like: ``` https://github.com/davidkane9/project-2 ``` ### Note that Github looks different depending on which page you go to, whether it is the main page (`github.com`), your account page (`github.com/your-user-name`) or the repository tab on your account page `github.com/your-user-name?tab=repositories`. The green button to create a new repo only appears on the main page (upper left) and on the repository tab on your account page (upper right). ### Exercise 2 Connect the `project-2` Github repo to an R project on your computer. Name the R project `project-2` also. (Don't forget the "tab" key trick.) Keeping the names of repos/projects aligned makes organization simpler. In the Console, run:
list.files()
CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### Your answer should include two files: `README.md` and `project-2.Rproj`. Positron will automatically restart and place you within the `project-2` R project. Recall that the definition of an R project is a directory which includes a `Rproj` file. If you run `tutorial.helpers::show_file("project-2.Rproj")` you will see that a `Rproj` file does not include the name of the project. The name of the project is taken from the directory in which it is located, i.e., the directory which contains the `Rproj` file. ### Exercise 3 Select `File -> New File -> Quarto Document ...`. Provide a title ("Quarto 2") and an author (you). Save the document as `quarto-2.qmd`. `Cmd/Ctrl + Shift + K`. In the Console, run:
list.files(all.files = TRUE)
CP/CR. The `all.files = TRUE` argument for `list.files()` generates all the files/directories, including the "hidden" ones whose names begin with a period, `.`. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 6) ``` ### Your answer should look like this: ``` > list.files(all.files = TRUE) [1] "." ".." ".git" ".gitignore" ".Rproj.user" "project-2.Rproj" [7] "quarto-2_files" "quarto-2.html" "quarto-2.qmd" "README.md" > ``` The single `.` refers to this directory while `..` refers to the directory above, which is `/Users/dkane/Desktop/projects` in this case. `.Rproj.user` and `.git` are directories, meant solely for the use of Positron and Git, respectively. The only other directory is `quarto-2_files`, a junk directory, created for the use of Quarto. We have discussed the other 5 files above. ### Exercise 4 Edit the `.gitignore` by adding `*Rproj` and `*_files`. In the Console, run:
tutorial.helpers::show_file(".gitignore")
CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 6) ``` ### Your answer should look like this: ``` > tutorial.helpers::show_file(".gitignore") .Rproj.user .Rhistory .RData .Ruserdata *Rproj *_files > ``` We could have specified the file/directory to ignore more precisely by using their exact names: `project-2.Rproj` and `quarto-2_files`. Doing so would avoid any weird complications if we end up adding other files to the project which, by coincidence, happen to have names which end with `Rproj` or `_files`. But that never (?) happens! And it is just easier to use the `*` versions. Note that `*` is a "regular expression" which matches any characters. So, Git will ignore any files or directories which end with `Rproj` or `_files`, including `project-2.Rproj` and `quarto-2_files`. ### Exercise 5 Using the Git tab in the Environment pane, add, commit and push the three remaining files: `.gitignore`, `quarto-2.qmd`, and `quarto-2.html`. Use a sensible commit message. From the Terminal, run `git log`. CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### Your answer should look like this: ``` Davids-MBP:project-2 dkane$ git log commit 8f414d418c039a79364b6fbe4c6de32acb1e6235 (HEAD -> main, origin/main, origin/HEAD) Author: davidkane9 <dave.kane@gmail.com> Date: Tue Feb 20 14:38:54 2024 -0500 initial version commit 4abced5c8c5b3dcd3a26d9efdce126031d8a0a0b Author: David Kane <dave.kane@gmail.com> Date: Tue Feb 20 14:26:05 2024 -0500 Initial commit Davids-MBP:project-2 dkane$ ``` There have been two commits in this repo. The first was generated automatically when we create the repo. The second was the one we just committed by hand, along with the commit message "initial version." Note how, next to the word "commit" there is a 40 character string of letters and numbers. This is the "hash" by which Github identifies each commit. The hash is always unique. ### Exercise 6 Remove everything below the YAML header from `quarto-2.qmd`. Add the code chunks from the previous section:
library(tidyverse) library(palmerpenguins)
penguins |> ggplot(aes(x = body_mass_g, y = flipper_length_mm, color = species)) + geom_point() + labs(title = "Penguins Body Mass compared to Flipper Length", x = "Body Mass", y = "Flipper Length")
Render the document. Copy-and-paste the "Warning" message which appears in `quarto-2.html`. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### Your answer should look like this: ``` Warning: Removed 2 rows containing missing values (`geom_point()`). ``` ### There are at least three problems with `quarto-2.html`: First, it displays the R code. Very few readers understand R code and even fewer want it to clutter up our pretty plot. Second, it shows the startup message printed by the **tidyverse** package. This is never useful to our viewers. They care about our data and graphics. Third, there is a warning message. We need to handle this sensibly, lest readers think that our results are suspect. ### Exercise 7 We need to make it so that we do not see this code or the output in the render `quarto-2.html` document. To do this, we will put `#| echo: false` and `#| message: false` before `library(tidyverse)` in the first code chunk. Render. In the Console, run:
tutorial.helpers::show_file("quarto-2.qmd")
CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 8) ``` ### `#| echo: false` makes it so that the code in the code chunk does not appear in the rendered HTML file.`#| message: false` prevents the display of any R messages, in this case ones generated by loading the **tiydverse** package. So, the previous code makes the whole code chunk with the libraries in it not visible in `quarto-2.html`. ### Exercise 8 Unfortunately, `quarto-2.html` still shows the code which creates the plot. So, before `penguins` in the second code chunk, add `#| echo: false`. Render the document. In the Console, run:
tutorial.helpers::show_file("quarto-2.qmd")
CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### The `#| echo: false` makes it so that the code in the code chunk --- in this case, the code which create our plot --- does not appear in the rendered HTML. Except for the Warning, `quarto-2.html` is starting to look professional. ### Exercise 9 It is annoying to have to include `#| echo: false` in multiple code chunks. So, Quarto allows us to include a command in the YAML which will then be applied in every code chunk. Delete `#| echo: false` from the two code chunks. In the YAML header, add ``` execute: echo: false ``` In the Console, run:
tutorial.helpers::show_file("quarto-2.qmd")
CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 8) ``` ### Your answer should look like:
title: "Quarto 2" author: "David Kane" format: html execute: echo: false
#| message: false library(tidyverse) library(palmerpenguins)
penguins |> ggplot(aes(x = body_mass_g, y = flipper_length_mm, color = species)) + geom_point() + labs(title = "Penguins Body Mass compared to Flipper Length", x = "Body Mass", y = "Flipper Length")
Render `quarto-2.qmd` to make sure everything still works. Fix anything which doesn't. ### Exercise 10 We still have the Warning to deal with. From the Console, type `penguins` and hit Enter. (This will probably produce an error.) CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### Here is what I got: ``` > penguins Error: object 'penguins' not found > ``` Recall the distinction between QMD World and Console World. In the QMD World, we have loaded the **tidyverse** and **palmerpenguins** packages. The latter contains the `penguins` tibble and the former includes the functions for printing tibbles nicely. But in Console world, we haven't done those things. We restarted R at the beginning of this section. We need to explicitly `library()` those two packages. ### Exercise 11 Put your cursor in `quarto-2.qmd` on the `library(tidyverse)` line. Hit `Cmd/Ctrl + Enter`. Note how the code is pasted down in the Console and then run there. Your cursor automatically moves down one line in `quarto-2.qmd` to the `library(palmerpenguins)` line. Hit `Cmd/Ctrl + Enter` again. From the Console, run `search()`. CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### The return value from `search()` should include `"package:palmerpenguins"` along with all the packages which make up the *Tidyverse*, like **lubridate** and **forcats**. The key lesson is that the Console does not know about the QMD file and the QMD file does not know about the Console. You need to keep them in sync. ### Exercise 12 We have forgotten to label the code chunks. Not good! Add `#| label: setup` to the first code chunk and `#| label: make-plot` to the second. `Cmd/Ctrl + Shift + K` In the Console, run:
tutorial.helpers::show_file("quarto-2.qmd", chunk = "Last")
CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### `quarto-2.html` is unchanged. Label'ing code chunk does not affect the output, but it is still good practice. ### Exercise 13 From the Console, run `summary(penguins$body_mass_g)`. CP/CR. ```r question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3) ``` ### Your answer should look like this: ``` > summary(penguins$body_mass_g) Min. 1st Qu. Median Mean 3rd Qu. Max. NA's 2700 3550 4050 4202 4750 6300 2 > ``` Note the two missing values. This is what is causing the warning message. ### Exercise 14 There are two standard ways to get rid of a warning message. First, we can make deal with the substance of the issue, determine the problem with our code/data which is causing the warning and solve it. Second (and much easier) we can simply hide the warning, although in that case, we should really add a code comment explaining what is going on. Because this section has gone on long enough, we take the second approach. To the `make-plot` code chunk, add `#| warning: false`. Render `quarto-2.qmd`. In the Console, run:
tutorial.helpers::show_file("quarto-2.qmd", chunk = "Last") ````
CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3)
If you turn off warnings, you ought to add some code comments explaining why. A better approach, in this case, would have been to add a command like drop_na(body_mass_g)
to the pipe. This would have removed the two rows with missing data.
Press the Publish button. Choose RPubs. Include a sensible slug. (I chose quarto-2
. A slug should not have any spaces since it is a URL.) Copy/paste the full URL below.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 3)
Your answer should look like:
https://rpubs.com/dkane/quarto-2
Check out the Git tab. Note the "M" next to quarto-2.qmd
and quarto-2.html
. The "M" is Git's (and Positron's) way of telling us that the files have been Modified. Note, also, the new directory, rsconnect
. This is another directory, like quarto-2_files
, which does not belong on GitHub.
Add rsconnect
to .gitignore
. Commit and push .gitignore
, quarto-2.qmd
and quarto-2.html
. Use a sensible commit message like "published version."
From the Terminal, run git log -n 1
. CP/CR.
question_text(NULL, answer(NULL, correct = TRUE), allow_retry = TRUE, try_again_button = "Edit Answer", incorrect = NULL, rows = 8)
The -n 1
argument pulls up just the last commit.
This is the third time that we have started with nothing and gone all the way to publishing something on the web. Well done! The key steps are GitHub repo -> R project -> Quarto document -> HTML -> RPubs.
This tutorial covered more details in the usage of Git and GitHub. Some material was from R for Data Science (2e) by Hadley Wickham, Mine Çetinkaya-Rundel, and Garrett Grolemund.
The most useful reference for Git/GitHub is Happy Git and GitHub for the useR. Refer to that book whenever you have a problem.
Any scripts or data that you put into this service are public.
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.