R/url2totals.R

#' @title URL 2 Totals
#' @param url url for player
#' @description gets dataframe
#' @keywords NBA basketball-reference html
#' @importFrom magrittr %>%
#' @export
#' @examples
#' url2totals(url)

url2totals <- function(url) {

  cont <- getContent(url)

  if (length(cont) > 0) {

    df <- cont[[2]]

    df <- df %>%
      dplyr::rename(season = Season,
                    age = Age,
                    team = Tm,
                    league = Lg,
                    position = Pos,
                    games = G,
                    games_started = GS,
                    minutes_played = MP,
                    field_goals = FG,
                    field_goals_attempted = FGA,
                    field_goal_pct = `FG%`,
                    three_pt_fg = `3P`,
                    three_pts_attm = `3PA`,
                    three_pt_pct = `3P%`,
                    two_pt_fg = `2P`,
                    two_pt_attm = `2PA`,
                    two_pt_pct = `2P%`,
                    eff_fg_pct = `eFG%`,
                    ft_made = FT,
                    ft_attm = FTA,
                    ft_pct = `FT%`,
                    off_reb = ORB,
                    def_reb = DRB,
                    tot_reb = TRB,
                    assists = AST,
                    steals = STL,
                    blocks = BLK,
                    turnovers = TOV,
                    fouls = PF,
                    points = PTS)

    df <- df[1:which(df$season=='Career')-1,]
    return (df)

  } else {

    return (NA)

  }
}
emilykuehler/basketballstatsR documentation built on May 31, 2019, 10:01 a.m.