Data-quality flags are stored in the metadata
slot of oce 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 contents of the data
slot, based on
such data-quality flags. For example, a common operation is to replace
erroneous data with NA
.
If the flags
within object
's metadata
slot is empty,
then object
is returned, unaltered.
Otherwise, handleFlags
examines object@metadata$flags
in the context of the flags
argument, and then
carries out actions that are specified by the actions
argument.
By default, this sets the returned data
entries to NA
,
wherever the corresponding metadata$flag
values
signal unreliable data. To maintain a hint as to why
data
were changed, metadata$flags
in the
returned value is a direct copy of the corresponding
entry in object
.
Usage
# S4 method for class 'argo'
handleFlags(
object = "oce",
flags = NULL,
actions = NULL,
where = NULL,
debug = getOption("oceDebug")
)
Arguments
- object
an argo object.
- flags
A list specifying flag values upon which actions will be taken. This can take two forms.
In the first form, the list has named elements each containing a vector of integers. For example, salinities flagged with values of 1 or 3: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 holding a single unnamed vector, and this means to apply the actions to all the data entries. For example,flags=list(c(1,3:9))
means to apply not just to salinity and temperature, but to everything within thedata
slot.
If
flags
is not provided, thendefaultFlags()
is called, to try to determine a reasonable default.- actions
an optional list that contains items with names that match those in the
flags
argument. Ifactions
is not supplied, the default will be to set all values identified byflags
toNA
; this can also be specified by specifyingactions=list("NA")
. It is also possible to specify functions that calculate replacement values. These are provided withobject
as the single argument, and must return a replacement for the data item in question. See “Details” for the default that is used ifactions
is not supplied.- where
an optional character value that permits the function to work with objects that store flags in e.g.
object@metadata$flags$where
instead of inobject@metadata$flags
, and data withinobject@data$where
instead of withinobject@data
. The default value ofNULL
means to look withingobject@metadata
itself, and this is the default withinoce
. (The purpose ofwhere
is to makeoce
extensible by other packages, which may choose to store data two levels deep in thedata
slot.)- debug
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")
.
References
Wong, Annie, Robert Keeley, Thierry Carval, and Argo Data Management Team. "Argo Quality Control Manual for CTD and Trajectory Data," January 1, 2020.
https://archimer.ifremer.fr/doc/00228/33951/
.
See also
Other functions relating to data-quality flags:
defaultFlags()
,
handleFlags()
,
handleFlags,adp-method
,
handleFlags,ctd-method
,
handleFlags,oce-method
,
handleFlags,section-method
,
initializeFlagScheme()
,
initializeFlagScheme,ctd-method
,
initializeFlagScheme,oce-method
,
initializeFlagScheme,section-method
,
initializeFlagSchemeInternal()
,
initializeFlags()
,
initializeFlags,adp-method
,
initializeFlags,oce-method
,
initializeFlagsInternal()
,
setFlags()
,
setFlags,adp-method
,
setFlags,ctd-method
,
setFlags,oce-method
Other things related to argo data:
[[,argo-method
,
[[<-,argo-method
,
argo
,
argo-class
,
argoGrid()
,
argoNames2oceNames()
,
as.argo()
,
as.ctd.argo()
,
plot,argo-method
,
read.argo()
,
read.argo.copernicus()
,
subset,argo-method
,
summary,argo-method
Examples
library(oce)
data(argo)
argoNew <- handleFlags(argo)
# Demonstrate replacement, looking at the second profile
f <- argo[["salinityFlag"]][, 2]
df <- data.frame(flag = f, orig = argo[["salinity"]][, 2], new = argoNew[["salinity"]][, 2])
df[11:15, ] # notice line 13
#> flag orig new
#> 11 1 35.207 35.207
#> 12 1 35.207 35.207
#> 13 4 35.209 NA
#> 14 1 35.207 35.207
#> 15 1 35.207 35.207