Extract: Extract or Replace Parts of a Coords Object

ExtractR Documentation

Extract or Replace Parts of a Coords Object

Description

Extract or replace subsets of coords.

Usage

## S3 method for class 'coords'
x[i]

## S3 replacement method for class 'coords'
x[i] <- value

Arguments

x

a "coords" object.

i

indices specifying elements to extract or replace—see Extract.

value

a numeric, a numeric vector of coordinate values of length(i), or a "coords" object, possibly named.

Details

Subsetting a "coords" object (except by an empty index) will drop all attributes except fmt, latlon, names and valid. Indices referencing values greater than length(x) will throw a ⁠subscript out of bounds⁠ error. If names are not required, use unname(), see examples.

Replacement values may be a single numeric, a numeric vector of coordinate values of length(i), or a "coords" object, possibly with a "latlon" attribute. However, the "latlon" attribute of the replacement value is ignored if the "coords" object x has no corresponding attribute set. If replacement values are named, the names are also ignored; to replace names, use names<-() replacement form.

Value

a "coords" object.

Note

To extract and replace subsets of "waypoints" objects, simply use the base package [ and [<- operators, taking care not to exclude the latitude and longitude columns or "Name" column (if present), which could lead to undefined results.

See Also

"coords", Extract, unname().

Examples

## Continuing example from `as_coords()`...


## Named "coords" object in degrees and minutes with
## eight values each of latitude and longitude
dm

## Extract the first eight values
dm[1:8]

## Exclude the first eight values
dm[-8:0]

## Index odd-numbered values
(index <- as.logical(1:16 %% 2))
dm[index]

## Extract values without names
unname(dm)[1:4]

## Create "coords" object with updated position of Tally Ho
newpos <- as_coords(c(4930.342, -12411.580), fmt = 2)
latlon(newpos) <- c(TRUE, FALSE)
newpos

## Update position using the "coords" object as replacement value
dm[c(3, 11)] <- newpos
dm[c(3, 11)]

## Or, as latlon didn't actually change, use simple numeric vector
dm[c(3, 11)] <- c(4930.342, -12411.580)
dm[c(3, 11)]

rm(dm, index, newpos)


Waypoint documentation built on June 8, 2025, 11:10 a.m.