[[,argoFloats-method {argoFloats} | R Documentation |
Look up a Value Within an argoFloats Object
Description
This function provides an easy way to look up values within an argoFloats
object, without the need to know the exact structure of the data. The action
taken by [[
depends on the type
element in the metadata
slot of
the object (which is set by the function that created the object), on the
value of i
and, in some cases, on the value of j
; see “Details”.
Usage
## S4 method for signature 'argoFloats'
x[[i, j, ...]]
Arguments
x |
an |
i |
a character value that specifies the item to be looked up; see “Details”. |
j |
supplemental index value, used for some |
... |
ignored. |
Details
There are several possibilities, depending on the object type
, as
listed below. Note that these possibilities are checked in the
order listed here.
For all object types:
If
i
is"metadata"
then themetadata
slot ofx
is returned.Otherwise, if
i
is"data"
then thedata
slot ofx
is returned.Otherwise, if
i
is"cycle"
then a character vector of the cycle numbers is returned.Otherwise, if
i
is"processingLog"
then theprocessingLog
slot ofx
is returned.Otherwise, if
i
is"ID"
then a character vector of the ID numbers is returned.Otherwise, the following steps are taken, depending on
type
.
If
type
is"index"
, i.e. ifx
was created withgetIndex()
or withsubset,argoFloats-method()
acting on the result ofgetIndex()
, then:If
i
is numeric andj
is unspecified, theni
is taken to be an index that identifies the row(s) of the data frame that was constructed bygetIndex()
based on the remote index file downloaded from the Argo server. This has elementsfile
for the remote file name,date
for the date of the entry,latitude
andlongitude
for the float position, etc.If
i
is the name of an item in themetadata
slot, then that item is returned. The choices are:"destdir"
,"destfileRda"
,"filename"
,"ftpRoot"
,"header"
,"server"
,"type"
, and"url"
.Otherwise, if
i
is the name of an item in thedata
slot, then that item is returned. The choices are:"date"
,"date_update"
,"file"
,"institution"
,"latitude"
,"longitude"
,"ocean"
, and"profiler_type"
. Note that"time"
and"time_update"
may be used as synonyms for"date"
and"date_update"
.Otherwise, if
i=="index"
then that item from thedata
slot ofx
is returned. (For the possible names, see the previous item in this sub-list.)Otherwise, if
i
is an integer, then thei
-th row of theindex
item in thedata
slot is returned. This is a good way to learn the longitude and latitude of the profile, the file name on the server, etc.Otherwise, if
i
is"ID"
then the return value is developed from theindex$file
item within thedata
slot ofx
, in one of three cases:If
j
is not supplied, the return value is a vector holding the identifiers (character codes for numbers) for all the data files referred to in the index.Otherwise, if
j
is numeric, then the return value is a subset of the ID codes, as indexed byj
.Otherwise, an error is reported.
If
i
is"length"
, the number of remote files pointed to by the index is returned.
Otherwise, if
type
is"profiles"
, i.e. ifx
was created withgetProfiles()
, then:If
i
is numeric andj
is unspecified, then return the local file name(s) that are identified by usingi
as an index.If
i
is the name of an item in themetadata
slot, then that item is returned. The choices are:"type"
and"destdir"
.Otherwise, if
i
is the name of an item in thedata
slot, then that item is returned. There is only one choice:"file"
.If
i
is"length"
, the number of local file names that were downloaded bygetProfiles()
is returned.
Otherwise, if
type
is"argos"
, i.e. ifx
was created withreadProfiles()
, then:If
i
is equal to"argos"
, andj
is unspecified, then a list holding the oce::argo objects stored withinx
is returned.If
i
is equal to"argos"
, andj
is provided, then the associated oce::argo object is returned.If
i
is numeric andj
is unspecified, then return the argo objects identified by usingi
as an index.If
i
is the name of an item in themetadata
slot, then that item is returned. There is only choice,"type"
.Otherwise, if
i
is the name of an item in thedata
slot, then that item is returned as a named list. (At present, there is only one choice:"argos"
.)Otherwise, if
i
is"length"
then the number of oce-type argo objects inx
is returned.Otherwise, if
i
is a character value then it is taken to be an item within themetadata
ordata
slots of the argo objects stored inx
, and the returned value is a list containing that information with one (unnamed) item per profile. Ifj
is provided and equal to"byLevel"
, then the items from themetadata
are repeated (if necessary) and formed into matrix or vector of the same shape as the"pressure"
field; this can be convenient for computations involving items that only occur once per profile, such as"longitude"
, but it should not be used for items that are not level-specific, such as the various"HISTORY_*"
elements, which apply to a dataset, not to a levelOtherwise, NULL is reported.
Otherwise, an error is reported.
Value
the indicated item, or NULL if it is neither stored within the first argument nor computable from its contents.
Author(s)
Dan Kelley
References
Kelley, D. E., Harbin, J., & Richards, C. (2021). argoFloats: An R package for analyzing Argo data. Frontiers in Marine Science, (8), 636922. doi:10.3389/fmars.2021.635922
Examples
data(index)
# Full remote filename for first two item in index
paste0(index[["server"]], "/dac/", index[["cycle", 1:2]])
# File names and geographical locations of first 5 items in index
index5 <- subset(index, 1:5)
data.frame(file=gsub(".*/", "", index5[["file"]][1]),
lon=index5[["longitude"]],
lat=index5[["latitude"]])