Skip to contents

Appends ICES area columns to the HH table of a datras_raw object by matching HH$StatRec (ICES statistical rectangle codes, e.g. "39F0") against an internal lookup table derived from the official ICES shapefiles.

The lookup is purely table-based and requires no spatial packages at runtime.

Usage

add_ices_areas(
  x,
  vars = c("Area_Full", "Area_27", "Ecoregion"),
  verbose = TRUE
)

Arguments

x

A datras_raw object with a StatRec column in HH.

vars

Character vector naming which area columns to add. Allowed values are any subset of "Area_Full", "Area_27", "SubArea", "Division", "SubDivisio", "Ecoregion". Defaults to c("Area_Full", "Area_27", "Ecoregion").

verbose

Logical; if TRUE (default), prints a message summarising how many hauls were matched.

Value

The input object x with the requested columns added (or overwritten) in HH.

Details

The function matches on the StatRec column of HH. Hauls whose StatRec code is not found in the lookup table (e.g. for surveys outside the ICES area) receive NA in the added columns.

If a requested column already exists in HH, it is overwritten.

Examples

## Add default columns (Area_Full, Area_27, Ecoregion)
dab2 <- add_ices_areas(dab)
#> Matched 2660 of 2660 hauls to ICES areas.
head(dab2$HH[, c("StatRec", "Area_Full", "Area_27", "Ecoregion")])
#>   StatRec Area_Full Area_27         Ecoregion
#> 1    42F7    27.4.b     4.b Greater North Sea
#> 2    42F6    27.4.b     4.b Greater North Sea
#> 3    41F7    27.4.b     4.b Greater North Sea
#> 4    41F6    27.4.b     4.b Greater North Sea
#> 5    42F2    27.4.b     4.b Greater North Sea
#> 6    42F1    27.4.b     4.b Greater North Sea

## Add only Area_27
dab3 <- add_ices_areas(dab, vars = "Area_27")
#> Matched 2660 of 2660 hauls to ICES areas.