stock.Rd
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)
Prefix used for all instance variables of this stock. Can have multiple parts that will be concatentated together, see example.
Vector defining length groups, each entry defining the minimum value.
If TRUE, final lengthgroups value defines a group x:Inf
.
If FALSE, final lengthgroups value is the upper bound for the previous group.
A g3_stock
or g3_fleet
object to clone.
A g3_stock
or g3_fleet
.
For g3_stock_def
, can also be a list of stock objects.
Intially the array will be filled with this constant, e.g. 1
, 0
or NaN
Description of the array that will be included in models
Name of definition to extract, e.g. "minlen"
.
# 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"
# 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')
#> $imm
#> 1:2 2:3 3:4 4:5 5:6 6:7 7:8 8:9 9:10 10:Inf
#> 1 2 3 4 5 6 7 8 9 10
#> attr(,"class")
#> [1] "force_vector" "integer"
#>
#> $mat
#> 1:2 2:3 3:4 4:5 5:6 6:7 7:8 8:9 9:10 10:Inf
#> 1 2 3 4 5 6 7 8 9 10
#> attr(,"class")
#> [1] "force_vector" "integer"
#>
# 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