Skip to contents

track constructs track tables based on data.frame (the default), tibble, or data.table. track is a convenience function that executes track_df, track_tbl, or track_dt based on the value of the `table` parameter. Track tables can be used like the data structure they are build upon but with a notable difference: they have an extra attribute to store the projection of the track coordinates, and modifying the projection will automatically trigger the appropriate conversion of the coordinates.

Usage

track(x, y, z, t, id, ..., proj, origin, period, tz, format, table = "df")

track_df(x, y, z, t, id, ..., proj, origin, period, tz, format)

track_tbl(x, y, z, t, id, ..., proj, origin, period, tz, format)

track_dt(x, y, z, t, id, ..., proj, origin, period, tz, format)

Arguments

x, y, z

Numeric vectors representing the coordinates of the locations. x and y are required. z can be ignored if the trajectories are 2-dimensional. Note: if the vectors are not of the same length, the shorter ones will be recycled to match the length of the longer one.

t

A numeric vector or a vector of objects that can be coerced to date-time objects by as_datetime representing the times (or frames) at which each location was recorded. If numeric, the origin and period of the time points can be set using origin and period below.

id

A vector that can be coerced to a character vector by as.character representing the identity of the individual to which each location belong.

...

A set of name-value pairs. Arguments are evaluated sequentially, so you can refer to previously created elements. These arguments are processed with rlang::quos() and support unquote via !! and unquote-splice via !!!. Use := to create columns that start with a dot.

proj

A character string or a crs object (see st_crs for more information) representing the projection of the coordinates. Leave empty if the coordinates are not projected (e.g., output of video tracking). "+proj=longlat" is suitable for the output of most GPS trackers.

origin

Something that can be coerced to a date-time object by as_datetime representing the start date and time of the observations when t is a numeric vector.

period

A character vector in a shorthand format (e.g. "1 second") or ISO 8601 specification. This is used when t is a numeric vector to represent time unit of the observations. All unambiguous name units and abbreviations are supported, "m" stands for months, "M" for minutes unless ISO 8601 "P" modifier is present (see examples). Fractional units are supported but the fractional part is always converted to seconds. See period for more details.

tz

A time zone name. See OlsonNames.

format

A character string indicating the formatting of `t`. See strptime for how to specify this parameter.

When supplied parsing is performed by strptime(). For this reason consider using specialized parsing functions in lubridate.

table

A string indicating the class of the table on which the track table should be built. It can be a data.frame ("df", the default), a tibble ("tbl"), or a data.table ("dt").

Value

A track table, which is a colloquial term for an object of class

track.

Author

Simon Garnier, garnier@njit.edu

Examples

data(short_tracks)

t_df <- track(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t,
  id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek", table = "df")

t_df <- track_df(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t,
  id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek")

t_tbl <- track_tbl(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t,
id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek")

t_dt <- track_dt(x = short_tracks$x, y = short_tracks$y, t = short_tracks$t,
  id = short_tracks$id, proj = "+proj=longlat", tz = "Africa/Windhoek")