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)

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 x:Inf. If FALSE, final lengthgroups value is the upper bound for the previous group.

inner_stock

A g3_stock or g3_fleet object to clone.

stock

A g3_stock or g3_fleet.

init_value

Intially the array will be filled with this constant, e.g. 1, 0 or NaN

desc

Description of the array that will be included in models

name

Name of definition to extract, e.g. "minlen".

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")
#> length
#>    1:10  10:100 100:Inf 
#>       1       1       1 
#> attr(,"desc")
#> [1] "Mean weight"

# Retrieve the upperlen for the stock
g3_stock_def(stock, 'upperlen')
#> [1] Inf

# 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)
#> length
#>   1:10 10:100 
#>     NA     NA 

# 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)
#> area
#> area1 
#>    NA