The trackeR package provides infrastructure for handling running and cycling data from GPS-enabled tracking devices. A short demonstration of its functionality is provided below, based on data from running activities. A more comprehensive introduction to the package can be found in the vignette “Infrastructure for Running and Cycling Data”, which can be accessed by typing
vignette("trackeR", package = "trackeR")
trackeR can currently import files in the Training Centre XML (TCX) format and .db3 files (SQLite databases, used, for example, by devices from GPSports) through the corresponding functions readTCX() and readDB3(). It also offers experimental support for JSON files from Golden Cheetah via readJSON().
library("trackeR")
filepath <- system.file("extdata", "2013-06-08-090442.TCX", package = "trackeR")
runDF <- readTCX(file = filepath, timezone = "GMT")
These read functions return a data.frame
of the following structure
str(runDF)
## 'data.frame': 1191 obs. of 9 variables:
## $ time : POSIXct, format: "2013-06-08 08:04:42" "2013-06-08 08:04:43" ...
## $ latitude : num 51.4 51.4 51.4 51.4 51.4 ...
## $ longitude : num 1.04 1.04 1.04 1.04 1.04 ...
## $ altitude : num 6.2 6.2 6.2 6.2 6.2 ...
## $ distance : num 0 1.68 5.28 8.33 14.88 ...
## $ heart.rate: num 83 84 84 86 89 93 96 98 101 102 ...
## $ speed : num 0 0.594 1.416 1.928 2.614 ...
## $ cadence : num NA 54 74 97 97 97 97 98 97 97 ...
## $ power : num NA NA NA NA NA NA NA NA NA NA ...
That data.frame
can be used as an input to the constructor function for trackeR’s trackeRdata class, to produce a session-based and unit-aware object that can be used for further analyses.
runTr0 <- trackeRdata(runDF)
## Warning in sanityChecks(dat = dat, silent = silent): Observations with
## duplicated time stamps are removed.
The readContainer() function combines the two steps of importing the data and constructing the trackeRdata object.
runTr1 <- readContainer(filepath, type = "tcx", timezone = "GMT")
## Warning in sanityChecks(dat = dat, silent = silent): Observations with
## duplicated time stamps are removed.
identical(runTr0, runTr1)
## [1] TRUE
The readDirectory() function can be used to read all
supported files in a directory and produce the corresponding trackeRdata objects.
The package includes an example data set which can be accessed through
data("runs", package = "trackeR")
The default behaviour of the plot method for trackeRdata objects is to show how heart rate and pace evolve over the session.
plot(runs, session = 1:7)
The elevation profile of a training session is also accessible, here along with the pace.
plot(runs, session = 27, what = c("altitude", "pace"))
The route taken during a training session can also be plotted on maps from various sources e.g., from Google or OpenStreetMap. This can be done either on a static map
plotRoute(runs, session = 4, zoom = 13, source = "google")
or on an interactive map.
leafletRoute(runs, session = 8:13)