The trackeR package aims to fill the gap between the routine
collection of data from GPSenabled tracking devices and the
analyses of such data within the R ecosystem.
library(trackeR)
## Loading required package: zoo
##
## Attaching package: 'zoo'
## The following objects are masked from 'package:base':
##
## as.Date, as.Date.numeric
##
## Attaching package: 'trackeR'
## The following object is masked from 'package:base':
##
## append
filepath <- system.file("extdata/tcx", "2013-06-01-183220.TCX.gz", package = "trackeR") # data from training centre XML (tcx data)
runDF <- readTCX(file = filepath, timezone = "GMT") # reading a single file of TCX
str(runDF)
## 'data.frame': 3881 obs. of 11 variables:
## $ time : POSIXct, format: "2013-06-01 17:32:20" "2013-06-01 17:32:21" ...
## $ latitude : num 50.8 50.8 50.8 50.8 50.8 ...
## $ longitude : num -1.7 -1.7 -1.7 -1.7 -1.7 ...
## $ altitude : num 83.4 83.8 84 83.8 83.6 ...
## $ distance : num 1.26 3.3 7.12 11.12 16.76 ...
## $ heart_rate : num 56 61 61 71 71 74 74 85 85 85 ...
## $ speed : num 0.885 1.209 1.801 2.205 2.756 ...
## $ cadence_running: num 60 63 70 78 83 84 84 85 85 86 ...
## $ cadence_cycling: logi NA NA NA NA NA NA ...
## $ power : logi NA NA NA NA NA NA ...
## $ temperature : logi NA NA NA NA NA NA ...
## - attr(*, "sport")= chr "running"
## - attr(*, "file")= chr "C:/Users/linhp/App/R/R-4.2.2/library/trackeR/extdata/tcx/2013-06-01-183220.TCX.gz"
runTr0 <- trackeRdata(runDF) # contruct the trackerdata object
## Warning in sanity_checks(dat = dat, silent = silent): Observations with
## duplicated time stamps have been removed.
runTr0
## A trackeRdata object
## Sports: running
##
## Training coverage: from 2013-06-01 18:32:15 to 2013-06-01 19:37:56
## Number of sessions: 1
## Training duration: 1.09 h
##
## Units
##
## latitude degree cycling
## longitude degree cycling
## altitude m cycling
## distance m cycling
## heart_rate bpm cycling
## speed m_per_s cycling
## cadence_cycling rev_per_min cycling
## power W cycling
## temperature C cycling
## pace min_per_km cycling
## duration min cycling
## latitude degree running
## longitude degree running
## altitude m running
## distance m running
## heart_rate bpm running
## speed m_per_s running
## cadence_running steps_per_min running
## temperature C running
## pace min_per_km running
## duration min running
## latitude degree swimming
## longitude degree swimming
## altitude m swimming
## distance m swimming
## heart_rate bpm swimming
## speed m_per_s swimming
## temperature C swimming
## pace min_per_km swimming
## duration min swimming
readContainer - function is used to call single file
runTr1 <- readContainer(filepath, type = "tcx", timezone = "GMT") #read single file only - read container
## Warning in sanity_checks(dat = dat, silent = silent): Observations with
## duplicated time stamps have been removed.
identical(runTr0, runTr1)
## [1] TRUE
gpxDir <- system.file("extdata/gpx", package = "trackeR") #Data from strava (data gpx)
workouts <- readDirectory(gpxDir, verbose = FALSE) # Reading multiple file in a Directory
get_sport(workouts)
## [1] "running" "cycling" "swimming"
The function readDirectory() allows the user to read all
files of a supported format in a directory, rather than calling, e.g.,
readContainer() on each file separately
trackeR data ship into 2 kinds of data (1 session and 27 sessions)
test1 <- data("run", package = "trackeR")
test2 <- data("runs", package = "trackeR")
data("run", package = "trackeR")
data("runs", package = "trackeR")
plot(runs, session = 1:3)
plotRoute(runs, session = 4, zoom = 13)
## ℹ Map tiles by Stamen Design, under CC BY 3.0. Data by OpenStreetMap, under ODbL.
# Scalar Summary
Moving thershold <- definition on it: move or not
based on speed (moving or resting)
summary(runs, session = 1:2)
##
## *** Session 1 : running ***
##
## Session times: 2013-06-01 18:32:15 - 2013-06-01 19:37:56
## Distance: 14130.7 m
## Duration: 65.68 mins
## Moving time: 64.17 mins
## Average speed: 3.59 m_per_s
## Average speed moving: 3.67 m_per_s
## Average pace (per 1 km): 4:38 min:sec
## Average pace moving (per 1 km): 4:32 min:sec
## Average cadence running: 88.66 steps_per_min
## Average cadence cycling: NA rev_per_min
## Average cadence running moving: 88.87 steps_per_min
## Average cadence cycling moving: NA rev_per_min
## Average power: NA W
## Average power moving: NA W
## Average heart rate: 141.11 bpm
## Average heart rate moving: 141.13 bpm
## Average heart rate resting: 136.76 bpm
## Average temperature: NA C
## Total elevation gain: 94.2 m
## Work to rest ratio: 42.31
##
## *** Session 2 : running ***
##
## Session times: 2013-06-02 07:23:43 - 2013-06-02 08:09:47
## Distance: 9450.24 m
## Duration: 46.07 mins
## Moving time: 44.13 mins
## Average speed: 3.42 m_per_s
## Average speed moving: 3.57 m_per_s
## Average pace (per 1 km): 4:52 min:sec
## Average pace moving (per 1 km): 4:40 min:sec
## Average cadence running: 88.21 steps_per_min
## Average cadence cycling: NA rev_per_min
## Average cadence running moving: 88.25 steps_per_min
## Average cadence cycling moving: NA rev_per_min
## Average power: NA W
## Average power moving: NA W
## Average heart rate: 139.48 bpm
## Average heart rate moving: 139.44 bpm
## Average heart rate resting: 141.16 bpm
## Average temperature: NA C
## Total elevation gain: 124.52 m
## Work to rest ratio: 22.83
##
## Moving thresholds: 2.0 (cycling) 1.0 (running) 0.5 (swimming) m_per_s
## Unit reference sport: running
summary(runs, session = 1)
##
## *** Session 1 : running ***
##
## Session times: 2013-06-01 18:32:15 - 2013-06-01 19:37:56
## Distance: 14130.7 m
## Duration: 65.68 mins
## Moving time: 64.17 mins
## Average speed: 3.59 m_per_s
## Average speed moving: 3.67 m_per_s
## Average pace (per 1 km): 4:38 min:sec
## Average pace moving (per 1 km): 4:32 min:sec
## Average cadence running: 88.66 steps_per_min
## Average cadence cycling: NA rev_per_min
## Average cadence running moving: 88.87 steps_per_min
## Average cadence cycling moving: NA rev_per_min
## Average power: NA W
## Average power moving: NA W
## Average heart rate: 141.11 bpm
## Average heart rate moving: 141.13 bpm
## Average heart rate resting: 136.76 bpm
## Average temperature: NA C
## Total elevation gain: 94.2 m
## Work to rest ratio: 42.31
##
## Moving thresholds: 2.0 (cycling) 1.0 (running) 0.5 (swimming) m_per_s
## Unit reference sport: running
runSummaryFull <- summary(runs)
plot(runSummaryFull, group = c("total", "moving")) # not select any metrics
plot(runSummaryFull, group = c("total", "moving"),
what = c("avgSpeed", "distance", "duration", "avgHeartRate")) # select some metrics to visualise