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 parselat
/lon
/ele
/time
columns.If
latlon
, this will only parselat
/lon
. This is particularly useful for TCX files exported without time information, such as from Strava.If
advanced
, it will load everything from basic, plushr
/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.
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)
#> # A tibble: 4,442 × 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,437 more rows
attr(act_tbl, "title")
#> NULL
nrow(parse_tcx(example_tcx_file))
#> [1] 4442
nrow(parse_tcx(example_tcx_file, every = 100))
#> [1] 37
colnames(parse_tcx(example_tcx_file))
#> [1] "lat" "lon" "ele" "time"
colnames(parse_tcx(example_tcx_file, detail = "latlon"))
#> [1] "lat" "lon"
colnames(parse_tcx(example_tcx_file, detail = "advanced"))
#> [1] "lat" "lon" "ele" "time" "hr" "cad"