library(magrittr)
# 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)
Run the code above in your browser using DataLab