stock | R Documentation |
Define multi-dimensional storage for use in models, mostly to contain state about stocks.
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)
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 |
A |
stock |
A |
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. |
A g3_stock
with length groups
An array with dimensions matching the stock.
A g3_stock
without length groups
The definition of the given variable in the stock. If stock is a list, then a list with the definition of each will be returned.
A g3_stock
with identical dimensions to inner_stock but with a new name.
TRUE
iff stock is a g3_stock
object.
# 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")
# Can get definitions for multiple stocks in one go
stocks <- list(
imm = g3_stock(c('st', 'imm'), 1:10),
mat = g3_stock(c('st', 'mat'), 1:10) )
g3_stock_def(stocks, 'minlen')
# 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.