api_scrape: Scrape stats.nba.com API and return statsnbaR data

Description Usage Arguments Details Value ‘statsnbaR filters’ YAML ‘statsnbaR datatype’ YAML End-point YAML

Description

Perform a query on a recognised endpoint of stats.nba.com, and format the output as a data.frame with inferred data types for each attribute based on statsnbaR's internal YAML specifications.

Usage

1
api_scrape(endpoint, filters, method = NULL, ...)

Arguments

endpoint

Character string which identifies the statsnbaR endpoint

filters

Named list of statsnbaR key-value filters for the query

method

Optional user-supplied function to retrieve JSON from stats.nba.com

Details

The endpoints, data types returned and filter specifications are given in the internal YAML which is available on https://www.github.com/stephematician/statsnbaR/tree/master/data-raw/ADL.yaml

The YAML specifies four main things, the;

How the last three items are specified is briefly described in the following sections.

Value

A list of data.frames of the resultSets returned by stats.nba.com with inferred data types.

‘statsnbaR filters’ YAML

1
2
3
4
5
6
7
filters  :
    league :
        mapping : {
            NBA      : "00",    # NBA
            D-league : "20"     # D-League
            }
        default : NBA

This is hopefully fairly self-explanatory:

‘statsnbaR datatype’ YAML

The desired properties of the returned data types and/or a way to map them to desired types is specified in the YAML in a fashion similar to the following example:

1
2
3
4
5
6
7
8
9
data    :
    person_id :
        class   : numeric
  &active roster_status :
       class   : logical
       mapping : {
           0 : FALSE,    # not active
           1 : TRUE      # active player
           }

Things to note are:

End-point YAML

The endpoint defined in the YAML might look like

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
endpoints :
    PlayerCommon :
        api.name     : "commonallplayers"
        api.path     : "stats"
        api.referrer : "http://stats.nba.com/players"
        api.filters  :
            league       : "LeagueID"
        api.results :
            CommonAllPlayers : {
                person_id    : "person_id",
                }

stephematician/statsnbaR documentation built on May 30, 2019, 3:17 p.m.