Skip to contents

Assigns species groups to a data frame that links species codes to species groups. Species within a species group share catchability parameters. The species groups are defined by a look-up table (lookup), which is joined to data using left_join. Any previous id_species_group or species_group definitions in the data object are replaced.

Usage

assign_species_groups(data, lookup, verbose = FALSE, ...)

Arguments

data

a data frame, to which updated species groups will be added. data is intended to have the same structure as the object defining the species grouping from Edwards et al. 2023 (see the sp_groups element of inputsBio).

lookup

a look-up table that defines the species groups based on variables, e.g., species codes or taxonomic information. lookup must include fields for species group identifiers (id_species_group - integer) and species group names (species_group - character). The species group name can include spaces, but should not include punctuation characters. Additionally, the name should not include LaTeX special characters, e.g., underscores (_), ampersands (&), dollar signs ($) etc.

verbose

report species groups that are set to NA (i.e., for codes that are not species-specific).

...

additional arguments to left_join.

Value

A data frame, with updated species group identifiers (id_species_group) and names (species_group).

Note

id_species_group and species_group will be set to NA for codes that are not specific to an individual species.

References

Edwards, C.T.T.; Peatman, T.; Roberts, J.O.; Devine, J.A.; Hoyle, S.D. (2023). Updated fisheries risk assessment framework for seabirds in the Southern Hemisphere. New Zealand Aquatic Environment and Biodiversity Report No. 321. 103 p.

Examples

library(sefraInputs)

# get species groupings from Edwards et al. (2023)
data(inputsBio)
#> Warning: data set 'inputsBio' not found
assign("x", inputsBio[[1]][['sp_groups']])
#> Error: object 'inputsBio' not found

# Assign species groups based on genus
y <- data.frame(genus = c("Diomedea", "Thalassarche", "Phoebetria", "Macronectes", "Procellaria"), id_species_group = 1:5,
                species_group = c("Great albatross", "Mollymawks", "Sooty albatrosses", "Giant petrels", "Procellaria species"))
assign_species_groups(x, y, by = "genus")
#> Error: object 'x' not found

# Assign species groups based on family
y <- data.frame(family = c("Diomedeidae", "Procellariidae"),
                id_species_group = 1:2, species_group = c("Albatrosses", "Petrels"))
assign_species_groups(x, y)
#> Error: object 'x' not found