format: Format and Print Coords or Waypoints

formatR Documentation

Format and Print Coords or Waypoints

Description

Format and print objects of class "coords" or "waypoints".

Usage

## S3 method for class 'coords'
print(x, ..., max = NULL)

## S3 method for class 'waypoints'
print(x, ..., fmt = NULL, max = NULL)

## S3 method for class 'coords'
format(x, ..., usenames = TRUE, validate = TRUE, fmt = 0L)

## S3 method for class 'waypoints'
format(x, ..., usenames = TRUE, validate = TRUE, fmt = 0L)

ll_headers(width, fmt)

Arguments

x

object of class "coords" created by function as_coords(), or class "waypoints" created by function as_waypoints().

...

further arguments passed to or from other methods.

max

numeric or NULL, specifying the maximal number of entries to be printed. By default, when NULL, getOption("max.print") used.

fmt

integer, 1L, 2L or 3L, specifying the required coordinate format.

usenames

logical, whether or not to include names in formatted output; default TRUE.

validate

logical, whether or not to validate x before formatting; default TRUE.

width

character vector, used to match width of headers to formatted output.

Details

The format() methods for "coords" and "waypoints" objects output elegantly formatted character vector representations of their arguments, which are used by their respective print() methods.

Objects of class "coords" specified in degrees and minutes or in degrees, minutes and seconds and with a "latlon" attribute, and similarly specified "waypoints" objects are formatted with individual coordinate values followed by a capital letter representing the cardinal direction i.e., ‘⁠N⁠’, ‘⁠E⁠’, ‘⁠S⁠’ or ‘⁠W⁠’. "coords" objects lacking a "latlon" attribute have formatted values followed by two possible cardinal directions in parentheses i.e., ‘⁠(N/E)⁠’ for positive values and ‘⁠(S/W)⁠’ for negative values. Values of "coords" or "waypoints" objects in decimal degrees are formatted prefixed with their sign, if negative; cardinal direction is not shown, but for "coords" objects with a "latlon" attribute, the formatted values are suffixed by either ‘⁠lat⁠’ or ‘⁠lon⁠’.

Prior to formatting and printing, "coords" or "waypoints" objects are checked to ensure that their "valid" attribute (in the case of a "coords" object), or "validlat" and "validlon" attributes (in the case of a "waypoints" object) are present and all TRUE i.e., valid. If these attributes are found to contain any FALSE i.e. invalid values, a warning is issued and similarly, if these attributes are missing, a warning is issued and the objects are re-validated as described under validate().

The optional argument fmt may be used to specify the coordinate format desired for formatting or printing "coords" or "waypoints" objects, see the fmt argument for as_coords() and as_waypoints(); using the default, fmt = 0L, will format or print in the existing coordinate format.

ll_headers() outputs the headings ⁠"Latitude ... Longitude"⁠ formatted to the width of argument width, adjusted for format fmt and is primarily intended for use by the print() method for class "waypoints". Likewise argument validate is used by the print() methods for classes "coords" and "waypoints" to prevent unnecessary replicate validation and may otherwise be left as the default.

Value

The format() methods for both classes "coords" and "waypoints" return a character vector, respectively of length length(x) or nrow(x), and containing values formatted in decimal degrees, degrees and minutes, or degrees, minutes and seconds as appropriate.

See Also

format(), print(), "coords" and "waypoints".

Examples

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


## Print named "coords" object in degrees and minutes,
## implicitly using S3 print() method
dm

## Print explicitly using S3 print() method, specifying
## the maximal number of entries to be printed
print(dm, max = 14)

## Format as a fixed-width character vector,
## with names...
format(dm)

## ...or without them
format(dm, usenames = FALSE)

## Format as decimal degrees,
format(dm, fmt = 1)

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


## Print named "waypoints" object in degrees, minutes and seconds
## implicitly using S3 print() method
wp

## Print explicitly using S3 print() method, specifying
## the maximal number of entries to be printed
print(wp, max = 21)

## Print as degrees and minutes
print(wp, fmt = 2)

## Format as a fixed-width character vector,
## with names...
format(wp)

## ...or without them
format(wp, usenames = FALSE)

rm(dm, wp)



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