Skip to contents

Apply standard cleaning steps to a datras_raw / DATRASraw object.

Usage

clean_datras(
  x,
  aphias = NULL,
  years = NULL,
  quarters = NULL,
  gears = NULL,
  impute_missing_depth = FALSE,
  correct_species = TRUE,
  do_fishglob = FALSE,
  verbose = TRUE,
  explain_codes = FALSE
)

Arguments

x

A datras_raw object.

aphias

Optional numeric or character vector of Aphia IDs (Valid_Aphia) to retain.

years

Optional integer vector of years to retain.

quarters

Optional integer vector of quarters to retain.

gears

Optional character vector of gear codes to retain.

impute_missing_depth

Logical. If TRUE, missing haul depths are imputed using a smooth spatial GAM fitted to observed depths. Default: FALSE.

correct_species

Logical. If TRUE (default), species information is corrected using correct_species().

do_fishglob

Logical. If TRUE, apply clean_fishglob() instead of the standard DATRAS cleaning steps.

verbose

Logical. If TRUE (default), print a summary of HaulVal and StdSpecRecCode category counts and the number of hauls with missing Depth before cleaning. Ignored when do_fishglob = TRUE.

explain_codes

Logical. If TRUE, include a description of each HaulVal, StdSpecRecCode, and BySpecRecCode code in the printed summary. Default: FALSE. Only used when verbose = TRUE.

Value

A cleaned datras_raw object.

Details

For standard DATRAS data, the function removes invalid hauls, keeps only records with complete standard-species recording, optionally imputes missing haul depths, optionally corrects species information, and can subset the data by species, year, quarter, or gear.

If do_fishglob = TRUE, cleaning is delegated to clean_fishglob().

For standard DATRAS data (do_fishglob = FALSE), the following filters are applied before any optional subsetting:

  • only hauls with HaulVal %in% c("V", "N") are retained,

  • only records with StdSpecRecCode == 1 are retained.

If impute_missing_depth = TRUE, missing Depth values are predicted from a GAM of log(Depth) on a two-dimensional smooth of longitude and latitude. Note that this requires the R package mgcv to be installed.

Optional filtering by aphias, years, quarters, and gears is applied after cleaning.

Examples

if (FALSE) { # \dontrun{
## Basic cleaning
x_clean <- clean_datras(x)

## Restrict to selected years and quarters
x_clean <- clean_datras(x, years = 2018:2020, quarters = c(1, 3))

## Keep only selected species
x_clean <- clean_datras(x, aphias = c(126417, 126436))
} # }