diff --git a/NAMESPACE b/NAMESPACE index 36cc3d50..20a934a1 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -16,6 +16,7 @@ export(league_members) export(league_name) export(league_size) export(league_teams) +export(moves_summary) export(player_info) export(pro_schedule) export(roster_moves) diff --git a/R/transactions.R b/R/transactions.R new file mode 100644 index 00000000..df2f2359 --- /dev/null +++ b/R/transactions.R @@ -0,0 +1,43 @@ +#' League transactions +#' +#' Summary of transactions and roster changes made during a season by team. +#' +#' @inheritParams ffl_api +#' @return A data frame of transaction counts by team. +#' @examples +#' moves_summary(leagueId = "42654852") +#' @importFrom tibble as_tibble +#' @export +moves_summary <- function(leagueId = ffl_id(), leagueHistory = FALSE, ...) { + dat <- ffl_api(leagueId, leagueHistory, view = "mTeam", ...) + if (leagueHistory) { + out <- rep(list(NA), length(dat$teams)) + for (i in seq_along(dat$members)) { + out[[i]] <- out_trans( + teams = dat$teams[[i]], + y = dat$seasonId[i], + w = dat$scoringPeriodId[i] + ) + } + } else { + out <- out_trans( + teams = dat$teams, + y = dat$seasonId, + w = dat$scoringPeriodId + ) + } + return(out) +} + +out_trans <- function(teams, y = NULL, w = NULL) { + teams$transactionCounter$matchupAcquisitionTotals <- NULL + x <- data.frame( + seasonId = y, + scoringPeriodId = w, + teamId = teams$id, + abbrev = factor(teams$abbrev, levels = teams$abbrev), + waiverRank = teams$waiverRank, + teams$transactionCounter + ) + as_tibble(x) +} diff --git a/man/moves_summary.Rd b/man/moves_summary.Rd new file mode 100644 index 00000000..145735c0 --- /dev/null +++ b/man/moves_summary.Rd @@ -0,0 +1,27 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/transactions.R +\name{moves_summary} +\alias{moves_summary} +\title{League transactions} +\usage{ +moves_summary(leagueId = ffl_id(), leagueHistory = FALSE, ...) +} +\arguments{ +\item{leagueId}{Numeric league ID or ESPN fantasy page URL. Defaults to +\code{getOption("fflr.leagueId")}. Function fails if no ID is found.} + +\item{leagueHistory}{logical; Should the \code{leagueHistory} version of the API +be called? If \code{TRUE}, a list of results is returned, with one element for +each historical year of the league.} + +\item{...}{Arguments passed to \code{\link[jsonlite:fromJSON]{jsonlite::fromJSON()}} for parsing.} +} +\value{ +A data frame of transaction counts by team. +} +\description{ +Summary of transactions and roster changes made during a season by team. +} +\examples{ +moves_summary(leagueId = "42654852") +}