cf_games()
retrieves data from the CrossFit Games API, lightly
pre-processed. If you need low level access to the API, use cf_request()
.
If no data is returned by the API, an empty tibble with zero columns and zero rows is returned.
You'll typically need to use tidyr::unnest_wider()
and tidyr::hoist()
to
further process this data.
Arguments
- year
The year to retrieve data for. Note that not all parameters will be valid for past years.
- ...
These dots are for future extensions and must be empty.
- division
The division to retrieve data for. One of the values in cf_division.
- n_pages
An optional integer to limit the number of pages returned. Each page will have a maximum of 100 rows returned. This is useful if you just want to explore the data without downloading all of it. If not specified, this will download all available data.
- progress
Should a progress bar be shown for longer downloads?
Examples
library(tidyr)
library(dplyr)
games <- cf_games(2021)
# 15 workouts in the 2021 CrossFit games
games %>%
unnest_wider(entrant) %>%
hoist(scores, two = 2) %>%
select(competitorName, two) %>%
unnest_wider(two) %>%
select(competitorName, score, breakdown)
#> # A tibble: 40 × 3
#> competitorName score breakdown
#> <chr> <chr> <chr>
#> 1 Justin Medeiros 58 58 pts
#> 2 Patrick Vellner 100 100 pts
#> 3 Brent Fikowski 82 82 pts
#> 4 Björgvin Karl Guðmundsson 76 76 pts
#> 5 Saxon Panchik 61 61 pts
#> 6 Jonne Koski 70 70 pts
#> 7 Guilherme Malheiros 85 85 pts
#> 8 Alex Vigneault 52 52 pts
#> 9 Lazar Đukić 64 64 pts
#> 10 Noah Ohlsen 40 40 pts
#> # … with 30 more rows
# What affiliates were the top 20 associated with?
# (This is also a way to find an affiliate ID)
games %>%
unnest_wider(entrant) %>%
slice(1:20) %>%
select(competitorName, affiliateId, affiliateName)
#> # A tibble: 20 × 3
#> competitorName affiliateId affiliateName
#> <chr> <chr> <chr>
#> 1 Justin Medeiros 1792 "CrossFit Fort Vancouver"
#> 2 Patrick Vellner 1918 "CrossFit Nanaimo"
#> 3 Brent Fikowski None ""
#> 4 Björgvin Karl Guðmundsson 4860 "CrossFit Hengill"
#> 5 Saxon Panchik 22505 "CrossFit Cliffside"
#> 6 Jonne Koski 7526 "CrossFit 10K"
#> 7 Guilherme Malheiros 10585 "Cavaleiros CrossFit"
#> 8 Alex Vigneault None ""
#> 9 Lazar Đukić 11487 "CrossFit NS"
#> 10 Noah Ohlsen 2509 "Peak 360 CrossFit"
#> 11 Scott Panchik 7991 "CrossFit Mentality"
#> 12 Travis Mayer 7104 "CrossFit UNTD"
#> 13 Jeffrey Adler 18059 "CrossFit Wonderland"
#> 14 Cole Sager 967 "CrossFit Spokane Valley"
#> 15 André Houdet 859 "CrossFit Butcher's Lab"
#> 16 Royce Dunne 10767 "CrossFit Torian"
#> 17 Bayden Brown 3235 "CrossFit Townsville"
#> 18 Henrik Haapalainen 7050 "CrossFit Basement"
#> 19 Jayson Hopper 21951 "CrossFit Simpsonville"
#> 20 Will Moorad 4917 "CrossFit Trivium"