parse_gpx {activatr}R Documentation

Parses a GPX file into a act_tbl

Description

This parses a standard GPS Exchange Format XML (GPX) file into an data frame with class act_tbl. See vignette("parsing") for examples.

Usage

parse_gpx(filename, detail = c("basic", "latlon", "advanced"), every = NA)

Arguments

filename

The GPX file to parse

detail

How much detail to parse from the GPX.

  • If basic (the default), this will parse lat / lon / ele / time columns.

  • If latlon, this will only parse lat/lon. This is particularly useful for GPX files exported without time information, such as from Strava.

  • If advanced, it will load everything from basic, plus hr / cad. This is most useful for files that have heart rate and cadence information.

every

Optional. If provided, determines how frequently points will be sampled from the file, so if 10 is provided, every tenth point will be selected. If omitted or set to 1, every point will be selected. Must be a positive integer.

This is most useful to quickly analyze a large file, since parsing is much faster when skipping 90% of the data points.

Value

A act_tbl with one row for each trackpoint in the . GPX (modified by every), and with the columns determined by detail.

lat

Latitude, a double in degrees between -90 and 90.

lon

Longitude, a double in degrees between -180 and 180.

ele

Elevation, a double in meters.

time

A date-time representing the time of the point.

hr

Heart rate, an int in beats per minute.

cad

Cadence, an int in one-foot steps per minute.

Additionally, attributes are set on the returned object containing top level data from the GPX. Each of these will be NA when not provided in the file.

filename

The filename this was parsed from, a string. This is always present, and is always the value of the filename parameter.

time

A date-time representing the time of the activity.

title

A string.

desc

A string.

type

A string.

See Also

https://en.wikipedia.org/wiki/GPS_Exchange_Format

https://www.topografix.com/gpx.asp

Examples

example_gpx_file <- system.file(
  "extdata",
  "running_example.gpx.gz",
  package = "activatr"
)
act_tbl <- parse_gpx(example_gpx_file)
print(act_tbl, n = 5)
attr(act_tbl, "title")

nrow(parse_gpx(example_gpx_file))
nrow(parse_gpx(example_gpx_file, every = 100))

colnames(parse_gpx(example_gpx_file))
colnames(parse_gpx(example_gpx_file, detail = "latlon"))
colnames(parse_gpx(example_gpx_file, detail = "advanced"))

[Package activatr version 0.2.0 Index]