usethisMake sure all changes from the fundamentals session are committed and pushed:
Every day of package development follows the same loop:
Pull requests add a review step between commit and merge to main.
%%{
init: {
'theme':'base',
'showCommitLabel': false,
'themeVariables': {
'git0':'#6cc644',
'git1':'#f39c12',
'commitLabelColor': '#325c65',
'commitLabelBackground':'#325c65'
}
}
}%%
gitGraph
commit id: " "
commit id: " "
commit id: " "
commit id: " "
branch "branch"
commit id: " "
commit id: " "
commit id: " "
commit id: " "
checkout main
merge "branch" tag: "PR review & merge"
commit id: " "
commit id: " "
Even when working alone, PRs are valuable:
mainWith collaborators, PRs also enable code review.
usethis PR helpers| Function | What it does |
|---|---|
pr_init("name") |
Create and switch to a new branch |
pr_push() |
Push branch, open PR on GitHub |
pr_pull() |
Pull latest changes on that branch from GitHub |
pr_merge_main() |
Merge latest changes from main into your branch |
pr_finish() |
Clean up after merge |
| Function | What it does |
|---|---|
pr_pause() |
Stash work, return to main |
pr_resume("name") |
Return to a branch |
pr_fetch(123) |
Check out someone else’s PR |
usethis PR helpers---
config:
theme: base
themeVariables:
fontSize: 30px
---
flowchart LR
A([main]) --> PI["pr_init()"] --> B([Branch])
B --> C[Write & test]
C --> PP["pr_push()"] --> D([GitHub PR])
D --> E{Review}
E --> C
E -->|Merged| F([main updated])
F --> PF["pr_finish()"] --> G([Clean state])
style A fill:#2d6a4f,color:#fff,stroke:none
style F fill:#2d6a4f,color:#fff,stroke:none
style G fill:#2d6a4f,color:#fff,stroke:none
style B fill:#1d3557,color:#fff,stroke:none
style D fill:#457b9d,color:#fff,stroke:none
style E fill:#e63946,color:#fff,stroke:none
style C fill:#333,color:#fff,stroke:#666
style PI fill:#f4a261,color:#000,stroke:none
style PP fill:#f4a261,color:#000,stroke:none
style PF fill:#f4a261,color:#000,stroke:none
Demonstrates the full workflow: https://usethis.r-lib.org/articles/pr-functions.html
mainTitle: Short, imperative - “Add foofy function”
Body:
Once the PR is approved and merged on GitHub:
mainIf you need to switch context mid-PR:
---
config:
theme: base
themeVariables:
fontSize: 20px
---
flowchart LR
A([main]) --> PI["pr_init()"] --> B([your branch])
B --> C[Write & test]
C --> PP["pr_push()"] --> D([GitHub PR])
D --> E{Review}
E -->|Changes needed| C
E -->|Approved & merged| F([main updated])
F --> PF["pr_finish()"] --> A
D --> PFetch["pr_fetch()"] --> G([reviewer's local])
G -->|review & comment| D
B --> PA["pr_pause()"] --> A
A --> PRe["pr_resume()"] --> B
style A fill:#2d6a4f,color:#fff,stroke:none
style F fill:#2d6a4f,color:#fff,stroke:none
style B fill:#1d3557,color:#fff,stroke:none
style G fill:#1d3557,color:#fff,stroke:none
style D fill:#457b9d,color:#fff,stroke:none
style E fill:#e63946,color:#fff,stroke:none
style C fill:#333,color:#fff,stroke:#666
style PI fill:#f4a261,color:#000,stroke:none
style PP fill:#f4a261,color:#000,stroke:none
style PF fill:#f4a261,color:#000,stroke:none
style PFetch fill:#f4a261,color:#000,stroke:none
style PA fill:#f4a261,color:#000,stroke:none
style PRe fill:#f4a261,color:#000,stroke:none
Demonstrates the full workflow: https://usethis.r-lib.org/articles/pr-functions.html
Your package works on your machine. But does it work on:
Continuous Integration automatically runs checks on every push
Create a new branch:
"check-standard": Runs R CMD check on several platforms when you push"test-coverage": Compute test coverage and report at codecov.ioCreates .github/workflows/R-CMD-check.yaml which runs R CMD check on:
The action also adds a badge to your README.Rmd:
Go to the Actions tab on your repo.
Each push triggers a workflow run.
Merge the PR on GitHub once CI is passing.
Run pr_finish() to clean up your branch after merging.
Air is a fast R code formatter - it automatically reformats your code on save.
Why it matters for collaboration:
In RStudio, change these settings:


Install the Air command line utility: https://posit-dev.github.io/air/cli.html
Review the diff on GitHub - you should see only formatting changes, no functional changes.
Let’s leave this PR and start a new one…
Now we’re back on main and can start a new branch for the next feature.
#' Calculate Biomass Index
#'
#' Calculates biomass index from CPUE and area swept.
#'
#' @param cpue Numeric vector of CPUE values
#' @param area_swept Numeric vector of area swept (e.g., km²)
#'
#' @return A numeric vector of biomass index values
#' @export
#'
#' @examples
#' salmon_cpue <- cpue(catch = 2, effort = 2)
#' biomass_index(cpue = salmon_cpue, area_swept = 5)
biomass_index <- function(cpue, area_swept) {
cpue * area_swept
}Commit when check() passes cleanly.
Pause the biomass PR and return to main:
On GitHub, review the biomass PR and merge once CI is passing.
usethis::pr_* helpers: https://usethis.r-lib.org/articles/pr-functions.html