R Package for @racently
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.
I recently wrote about an API for @racently. The next logical step was to build a package which wraps the API so that the data can easily be pulled into R.
The package is available here. It is still very much a work in progress: the API only exposes two endpoints, but both of them are wrapped in the package.
Installation
Install using {devtools}
.
devtools::install_github("datawookie/racently") library(racently)
Searching for Athletes
The search_athlete()
function makes it possible to search for an athlete by name using regular expressions for pattern matching.
Suppose I wanted to find athletes with the surname “Mann”.
search_athlete("Mann$") ## id slug name gender nationality twitter parkrun strava ## 1 016d0a83-1fc4-4613-81cb-ad3f09abac5e <NA> Garry Mann M <NA> <NA> NA NA ## 2 311aeaa2-155f-4566-a9fd-cf30afd67b16 <NA> Alec Mann M ZA <NA> NA NA ## 3 3207bed9-3dd4-42e7-aee5-c0a0347295c8 <NA> Michael Mann M <NA> <NA> NA NA ## 4 3c22a177-d03e-41c7-be31-a2bc77b2c61c <NA> Kevin Mann M ZA <NA> NA NA ## 5 52d681ea-8229-47ce-99ab-a4425b4dbcf0 <NA> Thomas Mann M <NA> <NA> NA NA ## 6 7ebe5ce2-6067-48d5-9c68-5f8167d6ab6e <NA> Julie Mann F <NA> <NA> NA NA ## 7 8437fcc7-3a38-4ecb-8708-82d148ea3368 <NA> Angie Mann F <NA> <NA> NA NA ## 8 94d8f1e6-4850-4708-8f70-3210b45d3bde <NA> Helen Mann F <NA> <NA> NA NA ## 9 bdd0716a-cbda-4c2e-8ef1-d5baab63ecfd <NA> Patrick Mann M <NA> <NA> NA NA ## 10 bebc042f-ad26-40f3-99d2-61a65e0296a2 <NA> Zeldi Mann F <NA> <NA> NA NA ## 11 d4cf93a6-69b4-40c4-949e-8444da403e17 <NA> Peter Mann M ZA <NA> NA NA ## 12 d676cb99-f272-4e9a-be04-fb6ec0aa7245 <NA> Steve Mann M ZA <NA> NA NA ## 13 d9897020-6e62-47c4-8481-ecbd19ddad12 <NA> Nicola Mann F <NA> <NA> NA NA ## 14 d9cc374d-521a-48bb-86dd-3ec6f05ef59f stuart-mann Stuart Mann M <NA> runningmann100 NA NA ## 15 df571960-0451-4cba-8483-17ccb4704680 <NA> Kim Mann F <NA> <NA> NA NA ## 16 e3c1dcc1-c783-4629-891b-f2e5a21daa87 <NA> Joanne Mann F <NA> <NA> NA NA ## 17 e4417318-66ef-42e3-b9f7-6a241b550e74 <NA> Jack Mann M <NA> <NA> NA NA ## 18 f2e9074c-ca75-4a99-b89d-07d377836c21 <NA> Roy Mann M ZA <NA> NA NA ## 19 f753bf50-4637-4cfb-89f6-efde8563ceff <NA> Luke Mann M ZA <NA> NA NA
We see that the somewhat legendary @runningmann100, Stuart Mann, is among the list of results.
Athlete Details
The athlete()
function allows you to find the results for a specific athlete, specified by id
(from the results above).
athlete("d9cc374d-521a-48bb-86dd-3ec6f05ef59f") ## $name ## [1] "Stuart Mann" ## ## $gender ## [1] "M" ## ## $results ## date race distance time club license ## 1 2019-06-09 Comrades 86.8 km 09:53:23 Fourways Road Runners NA ## 2 2019-02-09 Klerksdorp 42.2 km 03:54:09 NA NA ## 3 2018-11-24 Josiah Gumede 42.2 km 04:20:21 Fourways Road Runners 3388 ## 4 2018-10-28 Sapphire Coast 42.2 km 04:27:23 Fourways Road Runners 3388 ## 5 2018-09-02 Vaal River City 42.2 km 04:21:54 Fourways Road Runners 3388 ## 6 2018-06-10 Comrades 90.2 km 10:15:52 Fourways Road Runners 3388 ## 7 2018-05-20 RAC 10.0 km 01:14:21 Fourways Road Runners 3388 ## 8 2018-03-25 Umgeni Marathon 42.2 km 04:20:04 Fourways Road Runners 3388 ## 9 2018-03-10 Kosmos 3-in-1 42.2 km 04:18:51 NA NA ## 10 2018-02-25 Maritzburg 42.2 km 04:31:38 Fourways Road Runners 3388 ## 11 2017-12-03 Heroes Marathon 42.2 km 04:28:06 Fourways Road Runners 3388 ## 12 2017-11-05 Soweto Marathon 42.2 km 04:41:24 Fourways Road Runners 3388 ## 13 2017-09-17 Cape Town Marathon 42.2 km 04:25:06 Fourways Road Runners 3388 ## 14 2017-06-04 Comrades 86.7 km 10:40:59 Fourways Road Runners 3388 ## 15 2017-04-01 Arthur Cresswell Memorial 52.0 km 05:27:19 Fourways Road Runners 3388 ## 16 2017-03-26 Gaterite Challenge 42.2 km 04:14:54 Fourways Road Runners 3388 ## 17 2016-05-29 Comrades 89.2 km 10:19:06 Fourways Road Runners 9120 ## 18 2016-05-01 Deloitte Challenge 42.2 km 04:15:53 Team Vitality NA ## 19 2016-04-24 Chatsworth Freedom 52.0 km 05:36:06 Fourways Road Runners 9120 ## 20 2015-08-30 Mandela Day 42.2 km 04:48:16 Fourways Road Runners NA ## 21 2015-01-25 Johnson Crane Hire 42.2 km 04:28:35 Fourways Road Runners NA ## 22 2009-08-09 Mtunzini Bush 16.0 km 01:31:07 Fourways Road Runners 9120 ## 23 2009-05-24 Comrades 89.2 km 08:45:43 Fourways Road Runners 9120 ## 24 2008-11-28 Sani Stagger 42.2 km 05:25:19 Fourways Road Runners NA
The results include name, gender and the details of all of the relevant results in the system. As Stuart has pointed out, there are many results missing from his profile (he ticks off a marathon pretty much every weekend), but hey, like I said, this is a work in progress.
Future
We’ll be working hard to add more race results over the coming months (and cleaning up some of the existing data). There are also plans to expose more functionality on the API, which in turn will filter through to the R package.
R-bloggers.com offers daily e-mail updates about R news and tutorials about learning R and many other topics. Click here if you're looking to post or find an R/data-science job.
Want to share your content on R-bloggers? click here if you have a blog, or here if you don't.