Skip to contents

A template R package for building mizer extension packages. Clone it, rename it, and replace the placeholder code with your own extension logic. See Get Started for details.

What this template demonstrates

Every extension mechanism described in the mizer documentation is illustrated with working, commented code:

Mechanism Where What the template adds
setExtEncounter() R/constructor.R Allometric extra food source
setExtMort() R/constructor.R Size-dependent background mortality
project* S3 method R/rate-methods.R Seasonal encounter multiplier
setComponent() R/constructor.R + R/component-functions.R Dynamical plankton spectrum
getBiomass S3 override R/generic-methods.R Plankton biomass in output

The template also shows both kinds of extension package:

  • Dispatching (like this template and mizerShelf): defines a marker S4 class so mizer’s generic functions dispatch to extension-specific methods via NextMethod().
  • Metadata-only (like mizerStarvation): records the extension dependency without overriding any generic. Comments in the constructor explain which parts to keep or drop for this case.

Installation

# Install from GitHub (requires the development version of mizer)
pak::pak("sizespectrum/mizerExtensionTemplate")

Quick start

library(mizerExtensionTemplate)

params <- newExtensionTemplateParams(NS_species_params)
sim    <- project(params, t_max = 10)
plotBiomass(sim)   # includes a Plankton column

Using this template for your own extension

  1. Use this repo as a GitHub template (click “Use this template” on GitHub) or copy the files manually.

  2. Rename mizerExtensionTemplate → your package name throughout:

    • DESCRIPTION (Package, Title, Description, URL, BugReports)
    • R/mizerExtensionTemplate-class.R — rename the file and both setClass calls
    • R/mizerExtensionTemplate-package.R — update the requirement string
    • R/constructor.R — rename newExtensionTemplateParams()
    • R/rate-methods.R and R/generic-methods.R — rename all method suffixes
    • tests/ and vignettes/ — rename file names and internal references
  3. Decide: metadata-only or dispatching?
    For a metadata-only extension, delete R/mizerExtensionTemplate-class.R, remove the setClass() calls, and drop the coerceToExtensionClass() call at the end of the constructor. Keep params@extensions <- getRegisteredExtensions().

  4. Replace the placeholder extension logic with your own. Each mechanism in R/constructor.R is independent — delete the ones you don’t need.

  5. Regenerate the namespace and documentation:

    devtools::document()
    devtools::test()
    devtools::check()

Background reading