cleanPacFIN: Filter PacFIN samples.

Description Usage Arguments Details Value Author(s) See Also

View source: R/cleanPacFIN.R


cleanPacFIN filters out unsuitable samples from data, and converts fish lengths to cm. The original fields in the returned data are left untouched, with the exception of SEX, which is modified so that unidentified fish are labeled "U".


If there are CalCOM samples to be integrated with PacFIN data, run combineCalCOM first, otherwise run to cleanPacFIN as the first function in the workflow.


cleanPacFIN(Pdata, only_USINPFC = FALSE, keep_INPFC = NULL,
  remove_INPFC = NULL, badRecords = NULL,
  keep_gears = unique(Pdata$GRID)[order(unique(Pdata$GRID))],
  keep_sample_type = c("", "M"), keep_sample_method = "R",
  keep_length_type, keep_missing_lengths = FALSE, keep_CA = TRUE,
  CLEAN = TRUE, spp = NULL, verbose = TRUE)



a PacFIN dataset


a logical value. FALSE by default.


a set of INPFC areas. NULL by default.


a set of INPFC areas. NULL by default.


a set of sample identifiers. NULL by default.


A vector of character values specifying which gear types you want to label as unique fleets. Order the vector the same way you want the fleets numbered.


a set of sample types to retain. Default = c("", "M")


a set of sample methods to retain. Default = "R"


a set of length types to retain. There is no default value. Typically, users will want to retain c("", "F", "A") at a minimum, but should also think about adding NA, i.e., c("", "F", "A", NA).


a logical value. FALSE by default.


default TRUE. CA data often have no sample type or method, or INPFC area.


a logical value. Default is TRUE. If FALSE, return the original data unchanged, but report what would have been removed. Additional columns of information are added to the original data even if CLEAN = FALSE.


A character string giving the species name to ensure that the methods are species specific. Leave NULL if generic methods work for your species. Currently, sablefish is the only species with species-specific code.


A logical value specifying if output should be written to the screen or not. Good for testing and exploring your data but can be turned off when output indicates errors. The default value is TRUE.


INPFC Area specification

The US INPFC areas are c("VUS","CL","VN","COL","NC","SC","EU","CALCOM","CP","EK","MT","PS ")

"CalCOM" is included because the combineCalCOM function sets it, since CalCOM doesn't seem to record INPFC areas.

If only_USINPFC is TRUE, then only samples from the US INPFC areas will be retained.

If a set of INPFC areas are specified in keep_INPFC, then only samples from those areas will be retained.

If remove_INPFC specifies a set of INPFC areas, samples from those areas will be discarded.

Sample types and methods

SAMPLE_TYPEs may be (M=Market, R=Research, S=Special request, C=Commercial on-board). Only samples of type M are generally used.

SAMPLE_METHODs may be (R=Random, S=Stratified, N=Systematic, P=Purposive, X=Special). Only samples collected in random sampling are generally used.


The values created as new columns are for use by other functions in this package. In particular, fishyr and season are useful if there are multiple seasons (e.g., winter and summer, as in the petrale sole assessment), and the year is adjusted so that "winter" occurs in one year, rather than across two.

The fleet, fishery, and state columns are meant for use in stratifying the data according to the particulars of an assessment.

The sink command can be used to save the filtering report to a file, in addition to printing it to the console.


The input data filtered for desired areas and record types specified, with added columns

fishyr initialized from SAMPLE_YEAR
fleet initialized to 1
fishery initialized to 1
season initialized to 1. Change using getSeason
state initialized from SOURCE_AGID. Change using getState
lengthcm floored cm from FORK_LENGTH when available, otherwise FISH_LENGTH
geargroup the gear group associated with each GRID, from


Andi Stephens

See Also

cleanAges, getState, getSeason, sink

nwfsc-assess/PacFIN.Utilities documentation built on Jan. 3, 2020, 10:28 p.m.