Skip to content

Commit 7995f09

Browse files
committed
Add small executable example
1 parent bb5f8c9 commit 7995f09

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

R/tcxr.R

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,47 @@ library(XML)
88
#' @return A list containing the computed activity metrics, including the activity type.
99
#' @importFrom XML xmlTreeParse xmlRoot getNodeSet xmlGetAttr xmlValue
1010
#' @export
11+
#' @examples
12+
#' # Example usage of TCXRead function
13+
#' # Note: Ensure you have a valid TCX file at the specified path before running.
14+
#'
15+
#' # Create a temporary TCX file for testing
16+
#' temp_tcx_file <- tempfile(fileext = ".tcx")
17+
#' cat('<?xml version="1.0" encoding="UTF-8"?>
18+
#' <TrainingCenterDatabase xmlns="http://www.garmin.com/xmlschemas/TrainingCenterDatabase/v2">
19+
#' <Activities>
20+
#' <Activity Sport="Running">
21+
#' <Lap>
22+
#' <TotalTimeSeconds>1800</TotalTimeSeconds>
23+
#' <DistanceMeters>5000</DistanceMeters>
24+
#' <Calories>400</Calories>
25+
#' <Track>
26+
#' <Trackpoint>
27+
#' <AltitudeMeters>50</AltitudeMeters>
28+
#' <Extensions>
29+
#' <TPX>
30+
#' <Speed>2.78</Speed>
31+
#' <Watts>200</Watts>
32+
#' </TPX>
33+
#' </Extensions>
34+
#' <Cadence>90</Cadence>
35+
#' <HeartRateBpm>
36+
#' <Value>150</Value>
37+
#' </HeartRateBpm>
38+
#' </Trackpoint>
39+
#' </Track>
40+
#' </Lap>
41+
#' </Activity>
42+
#' </Activities>
43+
#' </TrainingCenterDatabase>', file = temp_tcx_file)
44+
#'
45+
#' # Read the TCX file
46+
#' tcx_data <- TCXRead(temp_tcx_file)
47+
#'
48+
#' # Print the parsed activity data
49+
#' print(tcx_data)
50+
#'
51+
#' unlink(temp_tcx_file)
1152
TCXRead <- function(file_path) {
1253
doc <- XML::xmlTreeParse(file_path, useInternalNodes = TRUE)
1354
root <- XML::xmlRoot(doc)

0 commit comments

Comments
 (0)