parse_tcx: Parses a TCX file into a 'act_tbl'

View source: R/parse.R

parse_tcxR Documentation

Parses a TCX file into a act_tbl

Description

This parses a standard Training Center XML (TCX) file into a data frame with class act_tbl. See vignette("parsing") for examples.

Usage

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

Arguments

filename

The TCX file to parse

detail

How much detail to parse from the TCX

  • 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 TCX 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 TCX (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 tibble containing top level data from the TCX. 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.

type

A string.

See Also

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

Examples

example_tcx_file <- system.file(
  "extdata",
  "running_example.tcx.gz",
  package = "activatr"
)
act_tbl <- parse_tcx(example_tcx_file)
print(act_tbl, n = 5)
attr(act_tbl, "title")

nrow(parse_tcx(example_tcx_file))
nrow(parse_tcx(example_tcx_file, every = 100))

colnames(parse_tcx(example_tcx_file))
colnames(parse_tcx(example_tcx_file, detail = "latlon"))
colnames(parse_tcx(example_tcx_file, detail = "advanced"))

dschafer/activatr documentation built on July 29, 2024, 3:18 a.m.