A collaborative R package for generating figures and analyses for the State of the Antarctic Environment (SOAE) report.
Open RStudio and run:
usethis::create_from_github("thesnakeguy/soae")Or clone the repository manually and open the .Rproj file.
install.packages(c(
"devtools",
"usethis",
"roxygen2",
"testthat"
))
⚠️ Do not uselibrary(soae)while developing. Use this instead:
devtools::load_all()This makes all functions in the package available immediately.
All functions must be added or edited directly in the R/ subdirectory. Create a thematic .R script if one doesn't exist yet — roxygen2::roxygenise() will scan the R/ folder and document all scripts automatically.
R/gfw.R # all things Global Fisheries Watch (gfw)
R/antarctic_theme.R # stores the shared ggplot theme
Use the roxygen2 template below as a starting point:
#' Short title of the function
#'
#' Longer description of what the function does.
#'
#' @param x Description of input
#' @return Description of output
#' @examples
#' my_function(1:10)
#' @export
my_function <- function(x) {
mean(x, na.rm = TRUE)
}Whenever you add or change a function, run:
roxygen2::roxygenize()This will:
- Generate/update documentation in
man/ - Update the
NAMESPACEfile automatically
⚠️ Never editNAMESPACEmanually.
If your code uses a new package (first check if it's not already listed), manually edit the DESCRIPTION file and add it under Imports::
Imports:
ggplot2,
dplyr,
sf
You can then add it to the soae-package.R file as an @importsFrom. Eg:
#' @importFrom stats sd
Do not use helper functions to edit
DESCRIPTION.
Before pushing changes, run:
devtools::check()Aim for:
- ✅ 0 errors
- ✅ 0 warnings
- ✅ 0 notes (or minimal notes)
# 1. Create a branch
git checkout -b feature/my-change
# 2. Stage and commit
git add .
git commit -m "Describe your change"
# 3. Push and open a Pull Request
git push origin feature/my-changeThen open a Pull Request on GitHub.
- Pull the latest changes from
main - Create a new branch
- Edit or add functions in the appropriate
R/*.Rscript - Update documentation:
roxygen2::roxygenize()
- Check the package:
devtools::check()
- Commit and push your branch
- Open a Pull Request
| Rule | Detail |
|---|---|
All functions go in R/ |
Organised by theme (e.g. gfw.R, oceanography.R etc) |
Run roxygenize() after every change |
Keeps docs and NAMESPACE in sync |
Run check() before merging |
Aim for 0 errors, 0 warnings |
Never edit NAMESPACE manually |
Always let roxygen2 handle it |
Edit DESCRIPTION manually for dependencies |
No helper functions |
| Keep functions simple and modular | One concern per function |
Use the shared antarctic_theme |
Consistent look across all figures |
Start a function with download if it pulls in external data |
Consistent nomenclature |
| Reference the type of function in the name | eg: plot_gfw_*** for gfw plotting functions |
If you're unsure about anything, open an issue
Happy coding 🚀