Add tag dimensions to g3_stock classes

g3s_tag(inner_stock, tag_ids, force_untagged = TRUE)

Arguments

inner_stock

A g3_stock that we extend with an area dimension

tag_ids

A vector of numeric tags the stock can have, generated by seq_along, e.g. Tag ID 0 is considered to be "untagged".

force_untagged

If TRUE, if "untagged" tag 0 isn't present it will be added.

Value

g3s_tag

A g3_stock with an additional 'tag' dimension.

When iterating over the stock, iterate over each tag in turn, tag will be set to the current integer area.

When interacting with another stock, iterate over each tag in turn, the variable name will depend on the scenario, e.g. prey_tag.

Examples

library(magrittr)

# Make a lookup of text names to integers
tags <- c('H1-00', 'H1-01')
tags <- structure(seq_along(tags), names = tags)

# prey_a can have any of these tags
prey_a <- g3_stock('prey_a', seq(1, 10)) %>% g3s_tag(tags)

# Use stock_instance to see what the array would look like
g3_stock_instance(prey_a)
#>         tag
#> length   untagged H1-00 H1-01
#>   1:2          NA    NA    NA
#>   2:3          NA    NA    NA
#>   3:4          NA    NA    NA
#>   4:5          NA    NA    NA
#>   5:6          NA    NA    NA
#>   6:7          NA    NA    NA
#>   7:8          NA    NA    NA
#>   8:9          NA    NA    NA
#>   9:10         NA    NA    NA
#>   10:Inf       NA    NA    NA