How to import Runkeeper GPX data in R

Do you use Runkeeper or keep a healthy collection of GPX files and want to use R to visualize the data? I realized that I hadn´t worked with GPX data in R, so my Runkeeper data seemed like a good place to start. You can find a guide for how to export your Runkeeper data to GPX files here. In my case, the exported data contained about 80 GPX files, and in this first test, I wanted to merge them all into a single data set and visualize them on a map. I used this R script:

# Load libraries
library(mapview)
library(sf)

# Path
path_gpx <- "C:\\Eget\\R\\Indata\\Runkeeper\\"

# Prepare for import
gpx_import <- st_sf(st_sfc())   # Create empty sf object, to add imported data to
st_crs(gpx_import) <- 4326   # Set crs to WGS 84 (EPSG 4326), same as the GPX data

# Create list with files to read
filenames <- list.files(path = path_gpx, pattern = ".gpx", full.names = TRUE)

# Loop through all files and import the "tracks" layer
for (filename in filenames) {
  gpx <- st_read(filename, layer = "tracks")
  gpx_import <- rbind(gpx_import, gpx)
}

# View result on map
mapview(gpx_import, lwd = 3, color = "CYAN")

Of course, the GPS files also contain each track point, all including elevation data. One of the files viewed in QGIS:

This gives you more options to manage and visualize the data and I´ll get back to this in an upcoming post.

1 Comment on “How to import Runkeeper GPX data in R

Leave a Reply

Your email address will not be published. Required fields are marked *

Please reload

Please Wait