Updated the queryAPI
and created a new function, stattle
that wraps it and makes walking easier. jsonlite
is great, but I started to bump
into some issues with dplyr::bind_rows
. Right now these two functions play nice together, but needs to be further tested.
## source the functions
u = "https://gist.githubusercontent.com/Btibert3/8f3671af30c8d1afc555/raw/4d620b99cd6c8df3aa17a6c84ac07056a5d479f3/queryAPI.r"
devtools::source_url(u)
u = "https://gist.githubusercontent.com/Btibert3/8f3671af30c8d1afc555/raw/4d620b99cd6c8df3aa17a6c84ac07056a5d479f3/stattle.r"
devtools::source_url(u)
We will handle these better shortly, but the code requires:
dplyr
httr
jsonlite
nhl_teams = stattle(TOKEN, ep='teams', walk=T)
length(nhl_teams)
names(nhl_teams[[1]])
The nhl_teams
object returns a list of lists. In the example above, there were two hits to the API, so length(nhl_teams)
is 2
. Nested below each of these parent lists are the data.
Collapse the team data into a dataframe.
dat = data.frame()
for (i in 1:length(nhl_teams)) {
tmp_dat = nhl_teams[[i]]$teams
dat = bind_rows(dat, tmp_dat)
rm(tmp_dat)
}
- put this into a more formal package
- leverage way better version control