TB and TC filescheck_raising() performs a suite of integrity checks on a pair of MEDITS
survey tables -- TB (catch-at-haul) and TC (biological subsamples) -- for
one survey year. All inconsistencies are written to a plain-text logfile; the
routine never stops at the first error, so you always get the full list of
issues detected.
check_raising(ResultDataTB, ResultDataTC, year, wd, suffix = NULL)Logical scalar: TRUE if the dataset passes all checks, FALSE
otherwise.
A data.frame containing the MEDITS TB
table for one or more years.
A data.frame containing the MEDITS TC
table for one or more years.
Single integer. The survey year to be checked.
Character string. A writable directory where sub-folders
Logfiles/ (and Graphs/, currently unused) will be created.
Optional character string appended to the logfile name. When
NULL (default) a timestamp-based suffix is generated automatically.
W. Zupa, I. Bitetto, M. T. Spedicato
The function executes five independent validations:
Weight consistency -- When more than one subsample exists for a
given haul/species in TC, the sum of
WEIGHT_OF_THE_FRACTION must equal TOTAL_WEIGHT_IN_THE_HAUL
recorded in TB.
Raising factor -- For each subsample the ratio \(molt\) given by WEIGHT_OF_THE_FRACTION / WEIGHT_OF_THE_SAMPLE_MEASURED must be \(\ge 1\).
Sex-specific numbers -- For every combination
haul * species * sex the raised total of individuals in TC
must match TB columns NB_OF_FEMALES, NB_OF_MALES
or NB_OF_UNDETERMINED.
Total individuals (TC -> TB) -- For every haul/species the sum of
raised numbers across all sexes in TC must equal
TOTAL_NUMBER_IN_THE_HAUL in TB. This catches cases where
an entire sex is missing from TC.
Internal TB consistency -- Within TB the sum of the three
sex-specific columns must equal TOTAL_NUMBER_IN_THE_HAUL for each
haul/species.
If any of these checks fails, an explanatory line is appended to the logfile
Logfiles/Logfile_.dat. The function finally returns a single
logical value: TRUE when no errors are detected, FALSE otherwise.
Tidy-evaluation is used inside the dplyr pipelines; the following symbols
are declared in globalVariables to avoid "no visible binding"
notes during R CMD check:
COUNTRY, YEAR, HAUL_NUMBER, GENUS, SPECIES,
WEIGHT_OF_THE_FRACTION, WEIGHT_OF_THE_SAMPLE_MEASURED,
NUMBER_OF_INDIVIDUALS_IN_THE_LENGTH_CLASS_AND_MATURITY_STAGE, SEX,
NB_OF_FEMALES, NB_OF_MALES, NB_OF_UNDETERMINED,
TOTAL_WEIGHT_IN_THE_HAUL, TOTAL_NUMBER_IN_THE_HAUL,
codedsex, N, molt, raised, RaisedSex,
RaisedTotal, n_subsamples, total_fraction,
SumSexTB.
dplyr for the data-manipulation verbs used under
the hood.
# \donttest{
# The following datasets come from the 'RoME' package demo data
DataTB <- RoME::TB
DataTC <- RoME::TC
res <- check_raising(DataTB, DataTC, year = 2015, wd = tempdir())
if (res) message("All checks passed!")
# }
Run the code above in your browser using DataLab