Title: | Access the 'Strava' API |
---|---|
Description: | Functions to access data from the 'Strava v3 API' <https://developers.strava.com/>. |
Authors: | Marcus W. Beck [cre], Pedro Villarroel [aut], Daniel Padfield [aut], Lorenzo Gaborini [aut], Niklas von Maltzahn [aut] |
Maintainer: | Marcus W. Beck <[email protected]> |
License: | CC0 |
Version: | 1.3.2 |
Built: | 2024-11-22 06:09:28 UTC |
Source: | https://github.com/fawda123/rStrava |
Get recent achievements, used internally in athl_fun
achievement_fun(prsd)
achievement_fun(prsd)
prsd |
parsed input list |
A data frame of recent achievements for the athlete. An empty list is returned if none found.
Get data for an athlete by web scraping, does not require authentication.
athl_fun(athl_num, trace = TRUE)
athl_fun(athl_num, trace = TRUE)
athl_num |
numeric vector of athlete id(s) used by Strava, as character string |
trace |
logical indicating if output is returned to console |
The athlete id is assigned to the user during registration with Strava and this must be known to use the function. Some users may have privacy settings that prevent public access to account information (a message indicating as such will be returned by the function). The function scrapes data using the following URL with the appended athlete id, e.g., https://www.strava.com/athletes/2837007. Opening the URL in a web browser can verify if the data can be scraped. Logging in to the Strava account on the website may also be required before using this function.
A list for each athlete, where each element is an additional list with elements for the athlete's information. The list elements are named using the athlete id numbers.
## single athlete athl_fun('2837007') ## multiple athletes athl_fun(c('2837007', '2527465'))
## single athlete athl_fun('2837007') ## multiple athletes athl_fun(c('2837007', '2527465'))
Get data for a single athlete by web scraping, does not require authentication.
athlind_fun(athl_num)
athlind_fun(athl_num)
athl_num |
numeric athlete id used by Strava, as character string |
A list with elements for the athlete's information.
Remove activities with no geographic data, usually manual entries
chk_nopolyline(act_data, ...) ## S3 method for class 'actframe' chk_nopolyline(act_data, ...)
chk_nopolyline(act_data, ...) ## S3 method for class 'actframe' chk_nopolyline(act_data, ...)
act_data |
a |
... |
arguments passed to or from other methods |
This function is used internally within get_elev_prof
and get_heat_map
to remove activities that cannot be plotted because they have no geographic information. This usually applies to activities that were manually entered.
act_data
with rows removed where no polylines were available, the original dataseset is returned if none were found. A warning is also returned indicating the row numbers that were removed if applicable.
Marcus Beck
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) act_data <- compile_activities(my_acts) chk_nopolyline(act_data) ## End(Not run)
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) act_data <- compile_activities(my_acts) chk_nopolyline(act_data) ## End(Not run)
converts a list of activities into a dataframe
compile_activities(actlist, acts = NULL, id = NULL, units = "metric")
compile_activities(actlist, acts = NULL, id = NULL, units = "metric")
actlist |
an activities list returned by |
acts |
numeric indicating which activities to compile starting with most recent, defaults to all |
id |
optional character vector to specify the id(s) of the activity/activities to plot, |
units |
chr string indicating metric or imperial |
each activity has a value for every column present across all activities, with NAs populating empty values
An activities frame object (actframe
that includes a data frame for the data and attributes for the distance, speed, and elevation units
Daniel Padfield
compile_club_activities
for compiling an activities list for club activities
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) acts_data <- compile_activities(my_acts) # show attributes attr(acts_data, 'unit_type') attr(acts_data, 'unit_vals') ## End(Not run)
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) acts_data <- compile_activities(my_acts) # show attributes attr(acts_data, 'unit_type') attr(acts_data, 'unit_vals') ## End(Not run)
convert a single activity list into a dataframe
compile_activity(x, columns)
compile_activity(x, columns)
x |
a list containing details of a single Strava activity |
columns |
a character vector of all the columns in the list of Strava activities. Produced automatically in |
used internally in compile_activities
dataframe where every column is an item from a list. Any missing columns rom the total number of columns
Daniel Padfield
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) acts <- get_activity_list(stoken) compile_activity(acts[1]) ## End(Not run)
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) acts <- get_activity_list(stoken) compile_activity(acts[1]) ## End(Not run)
Convert a set of streams of a single activity into a dataframe, with the retrieved columns.
compile_activity_streams(streams, id = NULL)
compile_activity_streams(streams, id = NULL)
streams |
a list containing details of the Strava streams of a single activity (output of |
id |
if not missing, the activity id of the stream (will be appended to the data.frame, if non-empty), as character vector |
used internally in get_activity_streams
data frame where every column is the stream data for the retrieved types.
Lorenzo Gaborini
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) act_id <- '351217692' streams <- get_streams(stoken, id = act_id, types = list('distance', 'latlng')) compile_activity_streams(streams, id = act_id) ## End(Not run)
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) act_id <- '351217692' streams <- get_streams(stoken, id = act_id, types = list('distance', 'latlng')) compile_activity_streams(streams, id = act_id) ## End(Not run)
converts a list of club activities into a dataframe
compile_club_activities(actlist)
compile_club_activities(actlist)
actlist |
a club activities list returned by |
each activity has a value for every column present across all activities, with NAs populating empty values
An data.frame
of the compiled activities from actlist
Marcus Beck
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) club_acts <- get_activity_list(stoken, id = 13502, club = TRUE) acts_data <- compile_club_activities(club_acts) ## End(Not run)
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) club_acts <- get_activity_list(stoken, id = 13502, club = TRUE) acts_data <- compile_club_activities(club_acts) ## End(Not run)
Cleans up the output of get_efforts_list() into a dataframe
compile_seg_effort(x)
compile_seg_effort(x)
x |
A list object produced by |
Used internally in compile_seg_efforts
. Can be used on the output of get_efforts_list
to compile the segment efforts of a single segment. Each call to get_efforts_list
returns a large list. This function returns a subset of this information.
A dataframe containing all of the efforts of a specific segment. The columns returned are athlete.id
, distance
, elapsed_time
, moving_time
, name
, start_date
and start_date_local
.
Daniel Padfield
## Not run: # set token stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # segments to get efforts from - use some parkruns segment <- 2269028 # get segment efforts efforts <- get_efforts_list(stoken, segment) # compile efforts efforts <- compile_seg_effort(efforts) ## End(Not run)
## Not run: # set token stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # segments to get efforts from - use some parkruns segment <- 2269028 # get segment efforts efforts <- get_efforts_list(stoken, segment) # compile efforts efforts <- compile_seg_effort(efforts) ## End(Not run)
Compiles the information of athletes from multiple segments
compile_seg_efforts(segment_ids, stoken)
compile_seg_efforts(segment_ids, stoken)
segment_ids |
A vector of segment ids from which to compile efforts |
stoken |
A |
Uses get_elev_prof
and compile_seg_effort
internally to compile efforts of multiple segments
A dataframe of the details of each segment effort
Daniel Padfield
## Not run: # set token stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # segments to get efforts from - use some parkruns segments <- c(2269028, 5954625) # compile segment efforts segments %>% purrr::map_df(., .f = compile_seg_efforts, stoken = my_token, .id = 'id') ## End(Not run)
## Not run: # set token stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # segments to get efforts from - use some parkruns segments <- c(2269028, 5954625) # compile segment efforts segments %>% purrr::map_df(., .f = compile_seg_efforts, stoken = my_token, .id = 'id') ## End(Not run)
Compile generation information on a segment
compile_segment(seglist)
compile_segment(seglist)
seglist |
a Strava segment list returned by |
compiles information for a segment
dataframe of all information given in a call from get_segment
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # compile segment info get_segment(stoken, id = '229781') %>% compile_segment # compile top ten leaderboard for the segment get_segment(stoken, id = '229781', request = "leaderboard") %>% compile_segment # compile all efforts for the authenticated user on the segment get_segment(stoken, id = '4483903', request = 'all_efforts') %>% compile_segment # compile the starred segments for the user get_segment(stoken, request = 'starred') %>% compile_segment ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # compile segment info get_segment(stoken, id = '229781') %>% compile_segment # compile top ten leaderboard for the segment get_segment(stoken, id = '229781', request = "leaderboard") %>% compile_segment # compile all efforts for the authenticated user on the segment get_segment(stoken, id = '4483903', request = 'all_efforts') %>% compile_segment # compile the starred segments for the user get_segment(stoken, request = 'starred') %>% compile_segment ## End(Not run)
This is a wrapper function to dplyr::filter which can be applied to an actframe object
## S3 method for class 'actframe' filter(.data, ...)
## S3 method for class 'actframe' filter(.data, ...)
.data |
an actframe object |
... |
Logical predicates defined in terms of the variables in .data |
an actframe object
## Not run: library(dplyr) # get actframe, all activities stoken <- httr::config( token = strava_oauth( app_name, app_client_id, app_secret, app_scope="activity:read_all" ) ) my_acts <- get_activity_list(stoken) act_data <- compile_activities(my_acts) # mutate act_data %>% filter(name %in% 'Morning Ride') ## End(Not run)
## Not run: library(dplyr) # get actframe, all activities stoken <- httr::config( token = strava_oauth( app_name, app_client_id, app_secret, app_scope="activity:read_all" ) ) my_acts <- get_activity_list(stoken) act_data <- compile_activities(my_acts) # mutate act_data %>% filter(name %in% 'Morning Ride') ## End(Not run)
Get athlete follow data, used internally in athl_fun
follow_fun(prsd)
follow_fun(prsd)
prsd |
parsed input list |
A data frame of counts of followers and following for the athlete. An empty list is returned if none found.
Get detailed data of an activity, including segment efforts
get_activity(id, stoken)
get_activity(id, stoken)
id |
character vector for id of the activity |
stoken |
A |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
The id for each activity can be viewed using results from get_activity_list
.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_activity('75861631', stoken) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_activity('75861631', stoken) ## End(Not run)
Get an activities list of the desired type (club, user)
get_activity_list(stoken, id = NULL, before = NULL, after = NULL, club = FALSE)
get_activity_list(stoken, id = NULL, before = NULL, after = NULL, club = FALSE)
stoken |
A |
id |
character vector for id of the activity or club if |
before |
date object for filtering activities before the indicated date |
after |
date object for filtering activities after the indicated date |
club |
logical if you want the activities of a club |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website. If retrieving activities using individual id
values, the output list returned contains additional information from the API and the results have not been tested with the functions in this package. It is better practice to retrieve all activities (as in the example below), use compile_activities
, and then filter by individual activities.
If retrieving club activities, the user for the API must be a member of the club.
A list of activities for further processing or plotting.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_activity_list(stoken) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_activity_list(stoken) ## End(Not run)
Retrieve streams for activities, and convert to a dataframe.
get_activity_streams(act_data, ...) ## S3 method for class 'list' get_activity_streams( act_data, stoken, acts = NULL, id = NULL, types = NULL, resolution = "high", series_type = "distance", ... ) ## S3 method for class 'actframe' get_activity_streams( act_data, stoken, types = NULL, resolution = "high", series_type = "distance", ... )
get_activity_streams(act_data, ...) ## S3 method for class 'list' get_activity_streams( act_data, stoken, acts = NULL, id = NULL, types = NULL, resolution = "high", series_type = "distance", ... ) ## S3 method for class 'actframe' get_activity_streams( act_data, stoken, types = NULL, resolution = "high", series_type = "distance", ... )
act_data |
an |
... |
arguments passed to or from other methods |
stoken |
A |
acts |
numeric indicating which activities to compile starting with most recent, defaults to all |
id |
optional character vector to specify the id(s) of the activity/activities to plot, |
types |
list indicating which streams to get for each activity, defaults to all available, see details. |
resolution |
chr string for the data resolution to retrieve, can be "low", "medium", "high", defaults to all |
series_type |
chr string for merging the data if |
Each activity has a value for every column present across all activities, with NAs populating missing values.
For the types
argument, the default is type = NULL
which will retrieve all available stream types. The available stream types can be any of time
, latlng
, distance
, altitude
, velocity_smooth
, heartrate
, cadence
, watts
, temp
, moving
, or grade_smooth
. To retrieve only a subset of the types, pass a list argument with the appropriate character strings to type
, e.g., type = list("time", "latlng", "distance")
.
Invalid HTTP requests (404 or 400 code) may sometimes occur for activities with incomplete data, e.g., stationary activities with no distance information. In such cases, changing the 'series_type' and 'resolution' arguments may be needed, e.g., 'series_type = "time"' and 'resolution = "medium"'.
A stream frame object (strframe
that includes a data frame for the stream data along with the units
Lorenzo Gaborini
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) strms_data <- get_activity_streams(my_acts, stoken, acts = 1:2) ## End(Not run)
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) strms_data <- get_activity_streams(my_acts, stoken, acts = 1:2) ## End(Not run)
Get basic athlete data for an athlete using an API request
get_athlete(stoken, id = NULL)
get_athlete(stoken, id = NULL)
stoken |
A |
id |
string of athlete |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
A list of athlete information including athlete name, location, followers, etc. as described here: https://strava.github.io/api/v3/athlete/.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_athlete(stoken, id = '2527465') ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_athlete(stoken, id = '2527465') ## End(Not run)
Get basic Strava data with requests that don't require pagination
get_basic(url_, stoken, queries = NULL)
get_basic(url_, stoken, queries = NULL)
url_ |
string of url for the request to the API |
stoken |
A |
queries |
list of additional queries or parameters |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # get basic user info get_basic('https://strava.com/api/v3/athlete', stoken) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # get basic user info get_basic('https://strava.com/api/v3/athlete', stoken) ## End(Not run)
Get club data for a given request
get_club(stoken, id = NULL, request = NULL)
get_club(stoken, id = NULL, request = NULL)
stoken |
A |
id |
character vector for id of the club, defaults to authenticated club of the athlete |
request |
chr string, must be "members", "activities" or |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_club(stoken) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_club(stoken) ## End(Not run)
Get distance from longitude and latitude points
get_dists(lon, lat)
get_dists(lon, lat)
lon |
chr string indicating name of longitude column in |
lat |
chr string indicating name of latitude column in |
Used internally in get_elev_prof
on objects returned by get_latlon
A vector of distances with the length as the number of rows in dat_in
Daniel Padfield
## Not run: # get activity data stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # get the latest activity acts_data <- compile_activities(my_acts)[1, ] # get lat, lon polyline <- acts_data$map.summary_polyline latlon <- get_latlon(polyline, key = mykey) # get distance get_dists(latlon$lon, latlon$lat) ## End(Not run)
## Not run: # get activity data stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # get the latest activity acts_data <- compile_activities(my_acts)[1, ] # get lat, lon polyline <- acts_data$map.summary_polyline latlon <- get_latlon(polyline, key = mykey) # get distance get_dists(latlon$lon, latlon$lat) ## End(Not run)
Get all the efforts in a segment if no queries are specified
get_efforts_list( stoken, id, athlete_id = NULL, start_date_local = NULL, end_date_local = NULL )
get_efforts_list( stoken, id, athlete_id = NULL, start_date_local = NULL, end_date_local = NULL )
stoken |
A |
id |
character string for id of the segment |
athlete_id |
character string for the athlete id for filtering the results |
start_date_local |
the start date for filtering the results |
end_date_local |
the end date for filtering the results |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_efforts_list(stoken, id = '229781') ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_efforts_list(stoken, id = '229781') ## End(Not run)
Create elevation profiles from activity data
get_elev_prof(act_data, ...) ## S3 method for class 'list' get_elev_prof( act_data, acts = 1, id = NULL, key, total = FALSE, expand = 10, units = "metric", fill = "darkblue", ... ) ## S3 method for class 'actframe' get_elev_prof( act_data, key, total = FALSE, expand = 10, fill = "darkblue", ... ) ## S3 method for class 'strframe' get_elev_prof(act_data, total = FALSE, expand = 10, fill = "darkblue", ...)
get_elev_prof(act_data, ...) ## S3 method for class 'list' get_elev_prof( act_data, acts = 1, id = NULL, key, total = FALSE, expand = 10, units = "metric", fill = "darkblue", ... ) ## S3 method for class 'actframe' get_elev_prof( act_data, key, total = FALSE, expand = 10, fill = "darkblue", ... ) ## S3 method for class 'strframe' get_elev_prof(act_data, total = FALSE, expand = 10, fill = "darkblue", ...)
act_data |
an activities list object returned by |
... |
arguments passed to or from other methods |
acts |
numeric value indicating which elements of |
id |
optional character vector to specify the id(s) of the activity/activities to plot, |
key |
chr string of Google API key for elevation data, passed to |
total |
logical indicating if elevations are plotted as cumulative climbed by distance |
expand |
a numeric multiplier for expanding the number of lat/lon points on straight lines. This can create a smoother elevation profile. Set |
units |
chr string indicating plot units as either metric or imperial, this has no effect if input data are already compiled with |
fill |
chr string of fill color for profile |
The Google API key is easy to obtain, follow instructions here: https://developers.google.com/maps/documentation/elevation/#api_key
A ggplot
of elevation profiles, facetted by activity id, date
Daniel Padfield, Marcus Beck
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # your unique key mykey <- 'Get Google API key' get_elev_prof(my_acts, acts = 1:2, key = mykey) # compile first, change units my_acts <- compile_activities(my_acts, acts = c(1:2), units = 'imperial') get_elev_prof(my_acts, key = mykey) ## End(Not run)
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # your unique key mykey <- 'Get Google API key' get_elev_prof(my_acts, acts = 1:2, key = mykey) # compile first, change units my_acts <- compile_activities(my_acts, acts = c(1:2), units = 'imperial') get_elev_prof(my_acts, key = mykey) ## End(Not run)
Explore segments within a bounded area
get_explore( stoken, bounds, activity_type = "riding", max_cat = NULL, min_cat = NULL )
get_explore( stoken, bounds, activity_type = "riding", max_cat = NULL, min_cat = NULL )
stoken |
A |
bounds |
chr string representing the comma separated list of bounding box corners 'sw.lat,sw.lng,ne.lat,ne.lng' or 'south, west, north, east', see the example |
activity_type |
chr string indicating activity type, "riding" or "running" |
max_cat |
numeric indicating the maximum climbing category |
min_cat |
numeric indicating the minimum climbing category |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) bnds <- "37.821362, -122.505373, 37.842038, -122.465977" get_explore(stoken, bnds) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) bnds <- "37.821362, -122.505373, 37.842038, -122.465977" get_explore(stoken, bnds) ## End(Not run)
Get gear details from its identifier
get_gear(id, stoken)
get_gear(id, stoken)
id |
string, identifier of the equipment item |
stoken |
A |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_gear("2275365", stoken) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_gear("2275365", stoken) ## End(Not run)
Makes a heat map from your activity data
get_heat_map(act_data, ...) ## S3 method for class 'list' get_heat_map( act_data, key, acts = 1, id = NULL, alpha = NULL, add_elev = FALSE, as_grad = FALSE, distlab = TRUE, distval = 0, size = 0.5, col = "red", expand = 10, maptype = "CartoDB.Positron", zoom = 14, units = "metric", ... ) ## S3 method for class 'actframe' get_heat_map( act_data, key, alpha = NULL, add_elev = FALSE, as_grad = FALSE, distlab = TRUE, distval = 0, size = 0.5, col = "red", expand = 10, maptype = "CartoDB.Positron", zoom = 14, ... ) ## S3 method for class 'strframe' get_heat_map( act_data, alpha = NULL, filltype = "elevation", distlab = TRUE, distval = 0, size = 0.5, col = "red", expand = 10, maptype = "CartoDB.Positron", zoom = 14, ... )
get_heat_map(act_data, ...) ## S3 method for class 'list' get_heat_map( act_data, key, acts = 1, id = NULL, alpha = NULL, add_elev = FALSE, as_grad = FALSE, distlab = TRUE, distval = 0, size = 0.5, col = "red", expand = 10, maptype = "CartoDB.Positron", zoom = 14, units = "metric", ... ) ## S3 method for class 'actframe' get_heat_map( act_data, key, alpha = NULL, add_elev = FALSE, as_grad = FALSE, distlab = TRUE, distval = 0, size = 0.5, col = "red", expand = 10, maptype = "CartoDB.Positron", zoom = 14, ... ) ## S3 method for class 'strframe' get_heat_map( act_data, alpha = NULL, filltype = "elevation", distlab = TRUE, distval = 0, size = 0.5, col = "red", expand = 10, maptype = "CartoDB.Positron", zoom = 14, ... )
act_data |
an activities list object returned by |
... |
arguments passed to or from other methods |
key |
chr string of Google API key for elevation data, passed to |
acts |
numeric indicating which activities to plot based on index in the activities list, defaults to most recent |
id |
optional character vector to specify the id(s) of the activity/activities to plot, |
alpha |
the opacity of the line desired. A single activity should be 1. Defaults to 0.5 |
add_elev |
logical indicating if elevation is shown by color shading on the activity lines |
as_grad |
logical indicating if elevation is plotted as percent gradient, applies only if |
distlab |
logical if distance labels are plotted along the route |
distval |
numeric indicating rounding factor for distance labels which has direct control on label density, see details |
size |
numeric indicating width of activity lines |
col |
chr string indicating either a single color of the activity lines if |
expand |
a numeric multiplier for expanding the number of lat/lon points on straight lines. This can create a smoother elevation gradient if |
maptype |
chr string indicating the provider for the basemap, see details |
zoom |
numeric indicating zoom factor for map tiles, higher numbers increase resolution |
units |
chr string indicating plot units as either metric or imperial, this has no effect if input data are already compiled with |
filltype |
chr string specifying which stream variable to use for filling line segments, applies only to |
uses get_latlon
to produce a dataframe of latitudes and longitudes to use in the map. Uses ggspatial to produce the map and ggplot2 to plot the route.
A Google API key is needed for the elevation data and must be included with function execution. The API key can be obtained following the instructions here: https://developers.google.com/maps/documentation/elevation/#api_key
The distval
argument is passed to the digits
argument of round
. This controls the density of the distance labels, e.g., 1 will plot all distances in sequence of 0.1, 0 will plot all distances in sequence of one, -1 will plot all distances in sequence of 10, etc.
The base map type is selected with the maptype
argument. The zoom
value specifies the resolution of the map. Use higher values to download map tiles with greater resolution, although this increases the download time. Acceptable options for maptype
include "OpenStreetMap"
, "OpenStreetMap.DE"
, "OpenStreetMap.France"
, "OpenStreetMap.HOT"
, "OpenTopoMap"
, "Esri.WorldStreetMap"
, "Esri.DeLorme"
, "Esri.WorldTopoMap"
, "Esri.WorldImagery"
, "Esri.WorldTerrain"
, "Esri.WorldShadedRelief"
, "Esri.OceanBasemap"
, "Esri.NatGeoWorldMap"
, "Esri.WorldGrayCanvas"
, "CartoDB.Positron"
, "CartoDB.PositronNoLabels"
, "CartoDB.PositronOnlyLabels"
, "CartoDB.DarkMatter"
, "CartoDB.DarkMatterNoLabels"
, "CartoDB.DarkMatterOnlyLabels"
, "CartoDB.Voyager"
, "CartoDB.VoyagerNoLabels"
, or "CartoDB.VoyagerOnlyLabels"
.
A ggplot
object showing a map with activity locations.
Daniel Padfield, Marcus Beck
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # default, requires Google key mykey <- 'Get Google API key' get_heat_map(my_acts, acts = 1, alpha = 1, key = mykey) # plot elevation on locations, requires key get_heat_map(my_acts, acts = 1, alpha = 1, key = mykey, add_elev = TRUE, col = 'Spectral', size = 2) # compile first, change units my_acts <- compile_activities(my_acts, acts = 156, units = 'imperial') get_heat_map(my_acts, key = mykey, alpha = 1, add_elev = T, col = 'Spectral', size = 2) ## End(Not run)
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # default, requires Google key mykey <- 'Get Google API key' get_heat_map(my_acts, acts = 1, alpha = 1, key = mykey) # plot elevation on locations, requires key get_heat_map(my_acts, acts = 1, alpha = 1, key = mykey, add_elev = TRUE, col = 'Spectral', size = 2) # compile first, change units my_acts <- compile_activities(my_acts, acts = 156, units = 'imperial') get_heat_map(my_acts, key = mykey, alpha = 1, add_elev = T, col = 'Spectral', size = 2) ## End(Not run)
Get KOMs/QOMs/CRs of an athlete
get_KOMs(id, stoken)
get_KOMs(id, stoken)
id |
string of athlete id |
stoken |
A |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_KOMs('2837007', stoken) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_KOMs('2837007', stoken) ## End(Not run)
Retrieve the laps of an activity
get_laps(stoken, id)
get_laps(stoken, id)
stoken |
A |
id |
character for id of the activity with the laps to request |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_laps(stoken, id = '351217692') ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_laps(stoken, id = '351217692') ## End(Not run)
get latitude and longitude from Google polyline
get_latlon(polyline, key)
get_latlon(polyline, key)
polyline |
a map polyline returned for an activity from the API |
key |
chr string of Google API key for elevation data, passed to |
dataframe of latitude and longitudes with a column for the unique identifier
Daniel Padfield, Marcus Beck
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) acts_data <- compile_activities(my_acts) # get lat and lon for a single activity polyline <- acts_data$map.summary_polyline[[1]] get_latlon(polyline, key = mykey) ## End(Not run)
## Not run: stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) acts_data <- compile_activities(my_acts) # get lat and lon for a single activity polyline <- acts_data$map.summary_polyline[[1]] get_latlon(polyline, key = mykey) ## End(Not run)
Retrieve the leaderboard of a segment
get_leaderboard(stoken, id, nleaders = 10, All = FALSE)
get_leaderboard(stoken, id, nleaders = 10, All = FALSE)
stoken |
A |
id |
character for id of the segment |
nleaders |
numeric for number of leaders to retrieve |
All |
logical to retrieve all of the list |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_leaderboard(stoken, id = '229781') ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_leaderboard(stoken, id = '229781') ## End(Not run)
Get several pages of one type of request to the API
get_pages( url_, stoken, per_page = 30, page_id = 1, page_max = 1, before = NULL, after = NULL, queries = NULL, All = FALSE )
get_pages( url_, stoken, per_page = 30, page_id = 1, page_max = 1, before = NULL, after = NULL, queries = NULL, All = FALSE )
url_ |
string of url for the request to the API |
stoken |
A |
per_page |
numeric indicating number of items retrieved per page (maximum 200) |
page_id |
numeric indicating page id |
page_max |
numeric indicating maximum number of pages to return |
before |
date object for filtering activities before the indicated date |
after |
date object for filtering activities after the indicated date |
queries |
list of additional queries to pass to the API |
All |
logical if you want all possible pages within the ratelimit constraint |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # get basic user info # returns 30 activities get_pages('https://strava.com/api/v3/activities', stoken) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # get basic user info # returns 30 activities get_pages('https://strava.com/api/v3/activities', stoken) ## End(Not run)
Retreive details about a specific segment
get_segment(stoken, id = NULL, request = NULL)
get_segment(stoken, id = NULL, request = NULL)
stoken |
A |
id |
character for id of the segment |
request |
chr string, must be "starred", "leaderboard", "all_efforts", or NULL for segment details |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website. The authenticated user must have an entry for a segment to return all efforts if request = "all_efforts"
. For request = "starred"
, set id = NULL
.
Data from an API request.
compile_segment
for converting the list
output to data.frame
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # get segment info get_segment(stoken, id = '229781') # get top ten leaderboard for the segment get_segment(stoken, id = '229781', request = "leaderboard") # get all efforts for the authenticated user on the segment get_segment(stoken, id = '4483903', request = 'all_efforts') # get the starred segments for the user get_segment(stoken, request = 'starred') ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) # get segment info get_segment(stoken, id = '229781') # get top ten leaderboard for the segment get_segment(stoken, id = '229781', request = "leaderboard") # get all efforts for the authenticated user on the segment get_segment(stoken, id = '4483903', request = 'all_efforts') # get the starred segments for the user get_segment(stoken, request = 'starred') ## End(Not run)
Allows the return of speed splits of multiple rides.
get_spdsplits(act_id, stoken, units = "metric")
get_spdsplits(act_id, stoken, units = "metric")
act_id |
a vector of activity IDs. These are easily found in the |
stoken |
A |
units |
chr string indicating plot units as either metric or imperial |
a data frame containing the splits of the activity or activities selected.
Marcus Beck
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # compile activities acts_data <- compile_activities(my_acts) # get spdsplits for all activities spd_splits <- purrr::map_df(acts_data$id, get_spdsplits, stoken = stoken, units = 'metric', .id = 'id') ## End(Not run)
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # compile activities acts_data <- compile_activities(my_acts) # get spdsplits for all activities spd_splits <- purrr::map_df(acts_data$id, get_spdsplits, stoken = stoken, units = 'metric', .id = 'id') ## End(Not run)
Retrieve a summary of the segments starred by an athlete
get_starred(stoken, id = NULL)
get_starred(stoken, id = NULL)
stoken |
A |
id |
character for id of the athlete, defaults to authenticated athlete |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_starred(stoken) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_starred(stoken) ## End(Not run)
Retrieve a Strava data stream for a single activity.
Internally called by get_activity_streams
.
get_streams( stoken, id, request = "activities", types = NULL, resolution = NULL, series_type = NULL )
get_streams( stoken, id, request = "activities", types = NULL, resolution = NULL, series_type = NULL )
stoken |
A |
id |
character for id of the request |
request |
chr string defining the stream type, must be "activities", "segment_efforts", "segments" |
types |
list of chr strings with any combination of "time" (seconds), "latlng", "distance" (meters), "altitude" (meters), "velocity_smooth" (meters per second), "heartrate" (bpm), "cadence" (rpm), "watts", "temp" (degrees Celsius), "moving" (boolean), or "grade_smooth" (percent) |
resolution |
chr string for the data resolution to retrieve, can be "low", "medium", "high", defaults to all |
series_type |
chr string for merging the data if |
Requires authentication stoken using the strava_oauth
function and a user-created API on the strava website. From the API documentation, 'streams' is the Strava term for the raw data associated with an activity.
Data from an API request.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_streams(stoken, id = '351217692', types = list('distance', 'latlng')) ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) get_streams(stoken, id = '351217692', types = list('distance', 'latlng')) ## End(Not run)
Get athlete location, used internally in athl_fun
location_fun(prsd)
location_fun(prsd)
prsd |
parsed input list |
A character string of the athlete location
Get distance and time for current month, used internally in athl_fun
monthly_fun(prsd)
monthly_fun(prsd)
prsd |
parsed input list |
A data frame of the current monthly distance and time for the athlete. An empty list is returned if none found.
This is a wrapper function to dplyr::mutate which can be applied to an actframe object
## S3 method for class 'actframe' mutate(.data, ...)
## S3 method for class 'actframe' mutate(.data, ...)
.data |
an actframe object |
... |
Name-value pairs of expressions. Use NULL to drop a variable. |
an actframe object
## Not run: library(dplyr) # get actframe, all activities stoken <- httr::config( token = strava_oauth( app_name, app_client_id, app_secret, app_scope="activity:read_all" ) ) my_acts <- get_activity_list(stoken) act_data <- compile_activities(my_acts) # mutate act_data %>% mutate(is_run=type=='Run') ## End(Not run)
## Not run: library(dplyr) # get actframe, all activities stoken <- httr::config( token = strava_oauth( app_name, app_client_id, app_secret, app_scope="activity:read_all" ) ) my_acts <- get_activity_list(stoken) act_data <- compile_activities(my_acts) # mutate act_data %>% mutate(is_run=type=='Run') ## End(Not run)
Plot average speed by splits for a single activity
plot_spdsplits(act_data, ...) ## S3 method for class 'list' plot_spdsplits( act_data, stoken, acts = 1, id = NULL, units = "metric", fill = "darkblue", ... ) ## Default S3 method: plot_spdsplits(act_data, stoken, units = "metric", fill = "darkblue", ...)
plot_spdsplits(act_data, ...) ## S3 method for class 'list' plot_spdsplits( act_data, stoken, acts = 1, id = NULL, units = "metric", fill = "darkblue", ... ) ## Default S3 method: plot_spdsplits(act_data, stoken, units = "metric", fill = "darkblue", ...)
act_data |
an activities list object returned by |
... |
arguments passed to other methods |
stoken |
A |
acts |
numeric indicating which activity to plot based on index in the activities list, defaults to most recent |
id |
optional character vector to specify the id(s) of the activity/activities to plot, |
units |
chr string indicating plot units as either metric or imperial |
fill |
chr string of fill color for profile |
The average speed per split is plotted, including a dashed line for the overall average. The final split is typically not a complete km or mile.
plot of average distance for each split value in the activity
Marcus Beck
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # default plot_spdsplits(my_acts, stoken, acts = 1) ## End(Not run)
## Not run: # get my activities stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) my_acts <- get_activity_list(stoken) # default plot_spdsplits(my_acts, stoken, acts = 1) ## End(Not run)
Checks the ratelimit values after the last request and stores the left requests in a global variable.
ratelimit(req)
ratelimit(req)
req |
value returned from the |
Requests to the Strava API are rate-limited. The default rate limit allows 600 requests every 15 minutes, with up to 30,000 requests per day. See the documentation at https://strava.github.io/api/#access.
A variable for the current limits.
Get last three recent activities, used internally in athl_fun
recent_fun(prsd)
recent_fun(prsd)
prsd |
parsed input list |
A data frame of recent activities for the athlete. An empty list is returned if none found.
Format before and after arguments for API query
seltime_fun(dtin, before = TRUE)
seltime_fun(dtin, before = TRUE)
dtin |
Date object for |
before |
logical indicattng if input is |
A numeric object as an epoch timestamp
# convert to epoch timestamp seltime_fun(Sys.Date()) # back to original as.POSIXct(seltime_fun(Sys.Date(), before = FALSE), tz = Sys.timezone(), origin = '1970-01-01')
# convert to epoch timestamp seltime_fun(Sys.Date()) # back to original as.POSIXct(seltime_fun(Sys.Date(), before = FALSE), tz = Sys.timezone(), origin = '1970-01-01')
Generate a token for the user and the desired scope. The user is sent to the strava authentication page if he/she hasn't given permission to the app yet, else, is sent to the app webpage.
strava_oauth( app_name, app_client_id, app_secret, app_scope = "public", cache = FALSE )
strava_oauth( app_name, app_client_id, app_secret, app_scope = "public", cache = FALSE )
app_name |
chr string for name of the app |
app_client_id |
chr string for ID received when the app was registered |
app_secret |
chr string for secret received when the app was registered |
app_scope |
chr string for scope of authentication, Must be "read" , "read_all", "profile:read_all", "profile:write", "activity:read", "activity:read_all" or "activity:write" |
cache |
logical to cache the token |
The app_name
, app_client_id
, and app_secret
are specific to the user and can be obtained by registering an app on the Strava API authentication page: http://strava.github.io/api/v3/oauth/. This requires a personal Strava account.
A Token2.0
object returned by oauth2.0_token
to be used with API function calls
## Not run: app_name <- 'myappname' # chosen by user app_client_id <- 'myid' # an integer, assigned by Strava app_secret <- 'xxxxxxxx' # an alphanumeric secret, assigned by Strava # create the authentication token stoken <- httr::config( token = strava_oauth( app_name, app_client_id, app_secret, app_scope="activity:read_all" ) ) # use authentication token get_athlete(stoken, id = '2837007') ## End(Not run)
## Not run: app_name <- 'myappname' # chosen by user app_client_id <- 'myid' # an integer, assigned by Strava app_secret <- 'xxxxxxxx' # an alphanumeric secret, assigned by Strava # create the authentication token stoken <- httr::config( token = strava_oauth( app_name, app_client_id, app_secret, app_scope="activity:read_all" ) ) # use authentication token get_athlete(stoken, id = '2837007') ## End(Not run)
Get athlete trophies, used internally in athl_fun
trophy_fun(prsd)
trophy_fun(prsd)
prsd |
parsed input list |
A data frame of trophies for the athlete. An empty list is returned if none found.
Set the url of activities for different activity lists
url_activities(id = NULL, club = FALSE)
url_activities(id = NULL, club = FALSE)
id |
string for id of the activity or club if |
club |
logical if you want the activities of a club |
This function concatenates appropriate strings so no authentication token is required. This is used internally by other functions.
The set url.
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) url_activities('2837007') ## End(Not run)
## Not run: # create authentication token # requires user created app name, id, and secret from Strava website stoken <- httr::config(token = strava_oauth(app_name, app_client_id, app_secret, cache = TRUE)) url_activities('2837007') ## End(Not run)
Set the url of the athlete to get data using an ID
url_athlete(id = NULL)
url_athlete(id = NULL)
id |
character of athlete id assigned by Strava, NULL will set the authenticated user URL |
used by other functions
A character string of the athlete URL used for API requests
Set the url of the clubs for the different requests
url_clubs(id = NULL, request = NULL)
url_clubs(id = NULL, request = NULL)
id |
character for id of the club, defaults to authenticated club of the athlete |
request |
chr string, must be "members", "activities" or |
Function is used internally within get_club
A url string.
url_clubs() url_clubs('123', request = 'members')
url_clubs() url_clubs('123', request = 'members')
Set the url of the equipment item to get data using an ID
url_gear(id)
url_gear(id)
id |
string of gear id assigned by Strava |
used by other functions
A character string of the gear URL used for API requests
Set the url for the different segment requests
url_segment(id = NULL, request = NULL)
url_segment(id = NULL, request = NULL)
id |
character for id of the segment if |
request |
chr string, must be "starred", "all_efforts", "leaderboard", "explore" or NULL for segment details |
Function is used internally within get_segment
, get_starred
, get_leaderboard
, get_efforts_list
, and get_explore
A url string.
url_segment() url_segment(id = '123', request = 'leaderboard')
url_segment() url_segment(id = '123', request = 'leaderboard')
Set the url for stream requests
url_streams(id, request = "activities", types = list("latlng"))
url_streams(id, request = "activities", types = list("latlng"))
id |
character for id of the request |
request |
chr string defining the stream type, must be "activities", "segment_efforts", "segments" |
types |
list of chr strings with any combination of "time", "latlng", "distance", "altitude", "velocity_smooth", "heartrate", "cadence", "watts", "temp", "moving", or "grade_smooth" |
Function is used internally within get_streams
. From the API documentation, 'streams' is the Strava term for the raw data associated with an activity.
A url string.
url_streams('123')
url_streams('123')