stock {gadget3} | R Documentation |
Gadget3 stock storage
Description
Define multi-dimensional storage for use in models, mostly to contain state about stocks.
Usage
g3_stock(var_name, lengthgroups, open_ended = TRUE)
g3_stock_instance(stock, init_value = NA, desc = "")
g3_fleet(var_name)
g3_stock_def(stock, name)
g3s_clone(inner_stock, var_name)
g3_is_stock(stock)
Arguments
var_name |
Prefix used for all instance variables of this stock. Can have multiple parts that will be concatentated together, see example. |
lengthgroups |
Vector defining length groups, each entry defining the minimum value. |
open_ended |
If TRUE, final lengthgroups value defines a group |
inner_stock |
|
stock |
|
init_value |
Intially the array will be filled with this constant, e.g. |
desc |
Description of the array that will be included in models |
name |
Name of definition to extract, e.g. |
Value
g3_stock
A g3_stock
with length groups
g3_stock_instance
An array with dimensions matching the stock.
g3_fleet
A g3_stock
without length groups
g3s_clone
A g3_stock
with identical dimensions to inner_stock but with a new name.
g3_is_stock
TRUE
iff stock is a g3_stock
object.
Examples
# Define a stock with 3 lengthgroups
stock <- g3_stock('name', c(1, 10, 100))
# Define a stock with a multi-part name. We can then dig out species name
stock <- g3_stock(c(species = 'ling', 'imm'), c(1, 10, 100))
stopifnot( stock$name == 'ling_imm' )
stopifnot( stock$name_parts[['species']] == 'ling' )
# Use stock_instance define storage for mean weight of stock,
# has dimensions matching what was defined above.
g3_stock_instance(stock, 1, "Mean weight")
# Retrieve the upperlen for the stock
g3_stock_def(stock, 'upperlen')
# Define a stock, not-open-ended. Now only 2 groups long
stock <- g3_stock('name', c(1, 10, 100), open_ended = FALSE)
# Use stock_instance to see what the array would look like
g3_stock_instance(stock)
# Fleets don't have lengthgroups
stock <- g3_fleet('name') %>% g3s_livesonareas(1)
# Use stock_instance to see what the array would look like
g3_stock_instance(stock)