Skip to contents

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.

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)
#> # A tibble: 4,433 × 4
#>     lat   lon   ele time               
#> * <dbl> <dbl> <dbl> <dttm>             
#> 1  37.8 -122.  17   2018-11-03 14:24:45
#> 2  37.8 -122.  16.8 2018-11-03 14:24:46
#> 3  37.8 -122.  17   2018-11-03 14:24:48
#> 4  37.8 -122.  17   2018-11-03 14:24:49
#> 5  37.8 -122.  17.2 2018-11-03 14:24:50
#> # ℹ 4,428 more rows
attr(act_tbl, "title")
#> [1] "Sunrise 15K PR (sub-8:00)"

nrow(parse_gpx(example_gpx_file))
#> [1] 4433
nrow(parse_gpx(example_gpx_file, every = 100))
#> [1] 44

colnames(parse_gpx(example_gpx_file))
#> [1] "lat"  "lon"  "ele"  "time"
colnames(parse_gpx(example_gpx_file, detail = "latlon"))
#> [1] "lat" "lon"
colnames(parse_gpx(example_gpx_file, detail = "advanced"))
#> [1] "lat"  "lon"  "ele"  "time" "hr"   "cad"