Updating our R packages, {kable} tables, and a first git collaboration
1. Setup
Create new repo on GitHub named eds221-day10-comp
Clone to make a local version-controlled R Project
1. Make a ggplot theme
Add a new Quarto document, saved in your project root as my_ggplot_theme.qmd
Attach the tidyverse and palmerpenguins packages
Create a plot from the data (whatever type you want)
Highly customize the theme() component (you can make it as bright / awful as you want - this is going to become a ggplot theme you can share with the world, so it’s up to you)
Keep this project OPEN (you’ll copy your custom theme in the next step…)
Here’s something awful just to remind you of what this can look like:
In a new session (so your existing project stays open), reopen the R Project for your R package you created last week
Install and Restart your package (this should also attach your package)
Remind yourself of what functions exist in the package (one way: in the Packages tab, click on your package name to see a list)
Create a new R script (.R )
Copy and paste just the theme() component of your customized ggplot graph that you just made into your empty R script. For the example above, that would just be:
Save your script using the same name as the function in the R folder (e.g. this one would be theme_eighties.R)
Add a Roxygen skeleton (recall: click within your function > Code > Insert Roxygen skeleton), and update the title (note that there aren’t any arguments / params)
devtools::document() to produce the R documentation for your new function
Install & restart
Try it out! Back in your other project, attach your package (which you just reinstalled), then make a plot that uses your custom theme from your package!
Stage, commit, & push changes back to your GitHub repo
Share your repo information (username/reponame) with your neighbor so they can install your package from GitHub! Recall: devtools::install_github("username/reponame")
Test your neighbors new & improved R package and try out their custom theme!
4. Making some nice tables in R
We’ve made a number of ggplot graphs, but we haven’t made any tables. Let’s learn one way!
Back in your eds221-day10-comp R Project, create a new R Markdown document
In the setup chunk, attach the tidyverse & kableExtra (note: there are a bunch of ways to make nice tables in R - see David Keyes’ post on How to make beautiful tables in R for more options)
Copy the contents of the table below to the clipboard, the use the datapasta Add-in to create a tibble stored as whale_sightings
Find a partner. Designate who is “Starter” and who is “Collaborator”.
Starter: Create a new version controlled R Project, make & push an update
Create a new repo called eds221-day10-collab (with a ReadMe)
Clone, create a new version-controlled R Project
Create a new .Rmd in the root (git_test.Rmd), delete everything below the first code chunk
Add a line of text in your .Rmd like “Hi partner!”
Stage, commit & push all changes back to your GitHub repo
Starter: Add a contributor
Go back to your eds221-day10-collab repo on GitHub
Go to Settings > Manage access > (Enter password if requested) > Invite collaborator > Enter Collaborator’s username or email
Collaborator: Accept invitation & clone repo, make an update
Check your email. You should receive the invitation to join the repo. Accept.
Clone (do NOT fork first) and create your own local R project
Pull just in case (this should say already up to date)
Open the git_test.Rmd
Add a new line to the .Rmd with a nice note below the line your partner added
Save the .Rmd, then stage, commit, pull & push
Check that the updates show up on GitHub
Starter: Pull & add something new to the .Rmd
PULL to get remote updates locally in RStudio
Open git_test.Rmd and see updated text from your partner
Add a new line of text to the .Rmd
Stage, commit, pull, then push
Collaborator: Pull & add something new to the .Rmd
PULL to get remote updates
Open git_test.Rmd and see updated text
Add a new line of text to the .Rmd
Stage, commit, pull, then push
Where goes what now on GitHub?
Both partners, go back to the repo on github for your collaboration
Go exploring (especially History & Blame)
Submit a new issue that references specific line(s) in your files
Still in GitHub, click on the git_test.Rmd file
Find a line that your partner wrote
Click the row number to the left of the line (or hold shift to select a range a lines) - the selected lines will turn yellow, and you should see a three dot menu button appear to the left of the code. Click on it, and choose “Reference in new issue”
Add a title and some text for your issue, and submit
Once you both have submitted an issue to your shared repo, check your partner’s issue, respond and close (resolve) the issue