Learn R Programming

Waypoint (version 1.1.0)

format: Format and Print Coords or Waypoints

Description

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

Usage

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

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

# S3 method for coords format(x, ..., usenames = TRUE)

# S3 method for waypoints format(x, ..., usenames = TRUE)

ll_headers(aswidth, fmt)

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.

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.

usenames

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

aswidth

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

fmt

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

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.

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().

ll_headers() outputs the headings "Latitude ... Longitude" formatted to the same width as argument aswidth, adjusted for format fmt and is primarily intended for use by the print() method for class "waypoints".

See Also

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

Examples

Run this code
## Continuing example from `as_coords()`...
# \dontshow{
   dm <-
       c(5130.4659, 4932.7726, 4806.4339, 3853.3696, 0.0000, -3706.7044, -5306.2869, -2514.4093,
	   -007.6754, 1823.9137, -12246.7203, -7702.1145, 0.0000, -1217.3178, 7331.0370, -5731.1536)
   names(dm) <- 
       rep(c("Nelson's Column", "Ostravice", "Tally Ho", "Washington Monument", "Null Island",
             "Tristan da Cunha", "Mawson Peak", "Silvio Pettirossi International Airport"), 2)
   invisible(as_coords(dm, fmt = 2))
   latlon(dm) <- rep(c(TRUE, FALSE), each = 8)
# }

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

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

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

###
## Continuing example from `as_waypoints()`...
# \dontshow{
   wp <- data.frame(
       name = c("Nelson's Column", "Ostravice", "Tally Ho", "Washington Monument", "Null Island",
                "Tristan da Cunha", "Mawson Peak", "Silvio Pettirossi International Airport"),
       lat = c(513027.95, 493246.36, 480626.04, 385322.18, 0, -370642.26, -530617.21, -251424.56),
       lon = c(-00740.53, 182354.82, -1224643.22, -770206.87, 0, -121719.07, 733102.22, -573109.21)
   )
   invisible(as_waypoints(wp, fmt = 3))
# }

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

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

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

rm(dm, wp)


Run the code above in your browser using DataLab