Data-quality flags are stored in the metadata
slot of oce-class
objects in a
list
named flags
.
The present function (a generic that has specialized versions
for various data classes) provides a way to
manipulate the core data based on
the data-quality flags. For example, a common operation is to replace suspicious
or erroneous data with NA
.
If metadata$flags
in the object supplied as the first argument
is empty, then that object is returned, unaltered.
Otherwise, handleFlags
analyses the data-quality flags within
the object, in relation to the flags
argument, and interprets
the action
argument to select an action to be applied to matched
data.
# S4 method for section
handleFlags(object, flags = NULL, actions = NULL,
debug = getOption("oceDebug"))
An object of section-class
.
A list
specifying flag values upon which
actions will be taken. This can take two forms. In the first, the
list has named elements each containing a vector of integers. For example,
salinities flagged with values of 1 or 3 through 9 would be specified
by flags=list(salinity=c(1,3:9))
. Several data items can be specified,
e.g. flags=list(salinity=c(1,3:9), temperature=c(1,3:9))
indicates
that the actions are to take place for both salinity and temperature.
In the second form, flags
is a list with unnamed vectors, and
this means to apply the actions to all the data entries; thus,
flags=list(c(1,3:9))
means to apply not just to salinity and temperature,
but also to everything else that is in the data
slot. If flags
is not provided, then defaultFlags
is called, to try to
determine a conservative default.
An optional list
that contains items with
names that match those in the flags
argument. If actions
is not supplied, the default will be to set all values identified by
flags
to NA
; this can also be specified by
specifying actions=list("NA")
. It is also possible to specify
functions that calculate replacement values. These are provided
with object
as the single argument, and must return a
replacement for the data item in question.
See “Details” for the default that is used if actions
is not supplied.
An optional integer specifying the degree of debugging, with
value 0 meaning to skip debugging and 1 or higher meaning to print some
information about the arguments and the data. It is usually a good idea to set
this to 1 for initial work with a dataset, to see which flags are being
handled for each data item. If not supplied, this defaults to the value of
getOption("oceDebug")
.
The default for flags
is based on
calling defaultFlags
based on the
metadata
in the first station in the section. If the
other stations have different flag schemes (which seems highly
unlikely for archived data), this will not work well, and indeed
the only way to proceed would be to use handleFlags,ctd-method
on the stations, individually.
1. https://www.nodc.noaa.gov/woce/woce_v3/wocedata_1/whp/exchange/exchange_format_desc.htm
Other functions relating to data-quality flags: defaultFlags
,
handleFlags,adp-method
,
handleFlags,argo-method
,
handleFlags,ctd-method
,
handleFlags
,
initializeFlagScheme,ctd-method
,
initializeFlagScheme,oce-method
,
initializeFlagScheme,section-method
,
initializeFlagScheme
,
initializeFlags,adp-method
,
initializeFlags,oce-method
,
initializeFlags
,
setFlags,adp-method
,
setFlags,ctd-method
,
setFlags,oce-method
, setFlags
Other things related to section
data: [[,section-method
,
[[<-,section-method
,
as.section
,
initializeFlagScheme,section-method
,
plot,section-method
,
read.section
, section-class
,
sectionAddStation
,
sectionGrid
, sectionSmooth
,
sectionSort
, section
,
subset,section-method
,
summary,section-method
# NOT RUN {
library(oce)
data(section)
section2 <- handleFlags(section, flags=c(1,3:9))
par(mfrow=c(2, 1))
plotTS(section)
plotTS(section2)
# }
Run the code above in your browser using DataLab