The [[ method works for all oce objects, i.e. objects inheriting from oce. The purpose is to insulate users from the internal details of oce objects, by looking for items within the various storage slots of the object. Items that are not actually stored in the object can also be extracted, including derived data such as potential temperature, the units of measurement for the data, data-quality flags, etc.

# S4 method for section
[[(x, i, j, ...)



a section object.


Character string indicating the name of an item to extract.


Optional additional information on the i item.


Optional additional information (ignored).


A two-step process is used to try to find the requested information. First, a class-specific function tries to find it, but if that fails, then a general function is used (see next section).

Details of the specialized section method

There are several possibilities, depending on the nature of i.

  • If i is the string "station", then the method will return a list() of ctd objects holding the station data. If j is also given, it specifies a station (or set of stations) to be returned. if j contains just a single value, then that station is returned, but otherwise a list is returned. If j is an integer, then the stations are specified by index, but if it is character, then stations are specified by the names stored within their metadata. (Missing stations yield NULL in the return value.)

  • If i is "station ID", then the IDs of the stations in the section are returned.

  • If i is "dynamic height", then an estimate of dynamic height is returned, as calculated with swDynamicHeight(x).

  • If i is "distance", then the distance along the section is returned, using geodDist().

  • If i is "depth", then a vector containing the depths of the stations is returned.

  • If i is "z", then a vector containing the z coordinates is returned.

  • If i is "theta" or "potential temperature", then the potential temperatures of all the stations are returned in one vector. Similarly, "spice" returns the property known as spice, using swSpice().

  • If i is a string ending with "Flag", then the characters prior to that ending are taken to be the name of a variable contained within the stations in the section. If this flag is available in the first station of the section, then the flag values are looked up for every station.

If j is "byStation", then a list is returned, with one (unnamed) item per station.

Details of the general method

If the specialized method produces no matches, the following generalized method is applied. As with the specialized method, the procedure hinges first on the values of i and, optionally, j. The work proceeds in steps, by testing a sequence of possible conditions in sequence.

  1. A check is made as to whether i names one of the standard oce slots. If so, [[ returns the slot contents of that slot. Thus, x[["metadata"]] will retrieve the metadata slot, while x[["data"]] and x[["processingLog"]] return those slots.

  2. If i is a string ending in the "Unit", then the characters preceding that string are taken to be the name of an item in the data object, and a list containing the unit is returned. This list consists of an item named unit, which is an expression(), and an item named scale, which is a string describing the measurement scale. If the string ends in " unit", e.g. x[["temperature unit"]] (note the space), then just the expression is returned, and if it ends in " scale", then just the scale is returned.

  3. If i is a string ending in "Flag", then the corresponding data-quality flag is returned (or NULL if there is no such flag). For example, x[["salinityFlag"]] returns a vector of salinity flags if x is a ctd object.

  4. If i is "sigmaTheta", then the value of swSigmaTheta() is called with x as the sole argument, and the results are returned. Similarly, swSigma0() is used if i="sigma0", and swSpice() is used if i="spice". Of course, these actions only make sense for objects that contain the relevant items within their data slot.

  5. After these possibilities are eliminated, the action depends on whether j has been provided. If j is not provided, or is the string "", then i is sought in the metadata slot, and then in the data slot, returning whichever is found first. In other words, if j is not provided, the metadata slot takes preference over the data slot. However, if j is provided, then it must be either the string "metadata" or "data", and it directs where to look.

If none of the above-listed conditions holds, then NULL is returned, without the issuance of a warning or error message. (This silent operation is employed so that [[ will behave like the normal R version.)

See also


data(section) length(section[["latitude"]])
#> [1] 2841
length(section[["latitude", "byStation"]])
#> [1] 124
# Vector of all salinities, for all stations Sv <- section[["salinity"]] # List of salinities, grouped by station Sl <- section[["salinity", "byStation"]] # First station salinities Sl[[1]]
#> [1] 36.1384 36.1103 35.9953 35.9372 35.8191