library(magrittr)
# Make a lookup so we can refer to areas by name
area_names <- g3_areas(c('a', 'b', 'c', 'd', 'e'))
stopifnot(area_names == c(a=1, b=2, c=3, d=4, e=5))
# Define a stock with 3 lengthgroups and 3 areas
stock <- g3_stock('name', c(1, 10, 100)) %>%
g3s_livesonareas(area_names[c('a', 'b', 'c')])
# Area variables will be defined, so you can refer to them in formulas:
g3a_migrate(stock, g3_parameterized("migrate_spring"),
run_f = ~area == area_b && cur_step == 2)
# Use stock_instance to see what the array would look like
g3_stock_instance(stock)
# Define a stock that groups areas into "north" and "south"
stock <- g3_stock('name', c(1, 10, 100)) %>%
g3s_areagroup(list(
north = area_names[c('a', 'b', 'c')],
south = area_names[c('d', 'e')]))
# Use stock_instance to see what the array would look like
g3_stock_instance(stock)
Run the code above in your browser using DataLab