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 columnUsing this template for your own extension
Use this repo as a GitHub template (click “Use this template” on GitHub) or copy the files manually.
-
Rename
mizerExtensionTemplate→ your package name throughout:-
DESCRIPTION(Package, Title, Description, URL, BugReports) -
R/mizerExtensionTemplate-class.R— rename the file and bothsetClasscalls -
R/mizerExtensionTemplate-package.R— update therequirementstring -
R/constructor.R— renamenewExtensionTemplateParams() -
R/rate-methods.RandR/generic-methods.R— rename all method suffixes -
tests/andvignettes/— rename file names and internal references
-
Decide: metadata-only or dispatching?
For a metadata-only extension, deleteR/mizerExtensionTemplate-class.R, remove thesetClass()calls, and drop thecoerceToExtensionClass()call at the end of the constructor. Keepparams@extensions <- getRegisteredExtensions().Replace the placeholder extension logic with your own. Each mechanism in
R/constructor.Ris independent — delete the ones you don’t need.-
Regenerate the namespace and documentation:
Background reading
- Extending mizer — all five extension mechanisms with worked examples.
-
Creating a mizer extension package — the concepts behind marker classes,
NextMethod()chaining, and composable extensions. - Using mizer extension packages — the user’s perspective on the extension chain.