gadget_update.gadgetstock: Update comonents of a gadgetstock object

View source: R/gadgetstock.R

gadget_update.gadgetstockR Documentation

Update comonents of a gadgetstock object

Description

Replace components of a gadgetstock with either new values or or content derived from an MFDB query.

Usage

## S3 method for class 'gadgetstock'
gadget_update(gf, component, ...)

Arguments

gf

The gadgetfile object to update

component

The component to update, or 'stock' to update the initial values

...

Either 0, data = (mfdb_query), or keys to update. See details.

If ... is 0, then the component is replaced with "doesgrow 0", for instance. If ... is data = mfdb_query, then the component is generated based on the data. How depends in which component:

stock

The query should contain age & length columns, inserts min/max for both

refweight

The query should contain age & length columns, inserted into refweight file

initialconditions

The query should contain area, age, length, number, mean columns

doesrenew

The query should contain year, step, area, age, length, number, mean columns

Finally, any other value of ... will update the relevant keys/values in that component.

naturalmortality is slightly different. It takes a single vector with one value per-age-group. It will be pre-populated with 0.2 for each age group.

doesgrow / growth can be populated with default values with gadget_update(gs, 'growth', 1)

gadget_update('refweight', data = data.frame(length = ..., weight = ...)) will also update minlength/maxlength/dl

gadget_update('refweight', data = data.frame(length = ..., alpha = ..., beta = ...)) will generate lengths via alpha * length^beta

doesmature / maturation will populate the maturityfile data file with all given parameters apart from maturityfunction, e.g. gadget_update('maturation',maturityfunction = 'constant', maturestocksandratios = c( ... ), coefficients = c( ... ))

doesrenew / recruitment can be populated from MFDB queries, e.g. gadget_update('doesrenew', number = data)

Examples

## Not run: 
library(magrittr)  # import %>% function
path <- './model'
gadgetstock('codimm', path, missingOkay = TRUE) %>%  # Create a skeleton if missing
   gadget_update('stock', minage = 2, maxage = 4) %>%
   gadget_update('stock', stockname = 'codmat') %>%  # Will change the name of the file we write
   gadget_update('doesmigrate', yearstepfile = gadgetfile('data/yearstepfile', components = list(
                                  data.frame(year = 1998, step = 1:4, 
                                             matrix = 'codmat-migration')))) %>%
   gadget_update('doesrenew', 0) %>%
   write.gadget.file(path)
   
## End(Not run)

Hafro/rgadget documentation built on July 21, 2022, 8:38 a.m.