Convert time-based data into a formula to lookup values

g3_timeareadata(lookup_name, df, value_field = "total_weight", areas = NULL)

Arguments

lookup_name

A unique name for this lookup, e.g. "igfs_landings".

df

A data.frame with any of columns out of age, area, year and step, finally value_field.

value_field

Column name that contains output value.

areas

Named integer vector of area names to integer values. See g3s_livesonareas.

Value

A formula object that looks up value_field for the current values of age, area, cur_year and cur_step, depending on the columns in df. If there's no match, return 0.

Examples

library(magrittr)
ling_imm <- g3_stock(c(species = 'ling', 'imm'), seq(20, 156, 4)) %>% g3s_age(3, 10)
ling_mat <- g3_stock(c(species = 'ling', 'mat'), seq(20, 156, 4)) %>% g3s_age(5, 15)
igfs <- g3_fleet('igfs')

igfs_landings <-
  structure(expand.grid(year=1990:1994, step=2, area=1, total_weight=1),
            area_group = list(`1` = 1))

# Generate a fleet predation action, use g3_timeareadata to supply landings
# NB: Since igfs_landings only contains values for step=2, there will be no
#     predation on other steps (since g3_timeareadata will return 0).
predate_action <- g3a_predate_fleet(
    igfs,
    list(ling_imm, ling_mat),
    suitabilities = list(
        ling_imm = g3_suitability_exponentiall50(
            g3_parameterized('lln.alpha', by_stock = 'species'),
            g3_parameterized('lln.l50', by_stock = 'species')),
        ling_mat = g3_suitability_exponentiall50(
            g3_parameterized('lln.alpha', by_stock = 'species'),
            g3_parameterized('lln.l50', by_stock = 'species'))),
    catchability = g3a_predate_catchability_totalfleet(
        g3_timeareadata('igfs_landings', igfs_landings)))