Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/k5cents/fflr

Get ESPN fantasy football data in R
https://github.com/k5cents/fflr

espn fantasy-football

Last synced: 3 months ago
JSON representation

Get ESPN fantasy football data in R

Awesome Lists containing this project

README

        

---
output: github_document
editor_options:
chunk_output_type: console
---

```{r include = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
warning = FALSE,
message = FALSE,
error = FALSE,
comment = "#>",
fig.path = "man/figures/README-",
fig.height = 4,
fig.width = 9,
out.width = "100%",
dpi = 300
)
if (!interactive()) {
options(width = 99)
}
```

# fflr

[![Lifecycle: experimental][life_badge]][life_link]
[![CRAN status][cran_badge]][cran_link]
![Downloads][dl_badge]
[![Codecov test coverage][cov_badge]][cov_link]
[![R build status][ga_badge]][ga_link]

The fflr package is used to query the [ESPN Fantasy Football API][api]. Get data
on fantasy football league members, teams, and individual athletes.

This package has been tested with a narrow subset of possible league settings.
If a function doesn't work as intended, please file an [issue on GitHub][iss].

## Installation

> [!IMPORTANT]
> As of 2024-05-17, fflr was removed from [CRAN][cran] for failure to comply
with the policy on internet resources. This issue arose when ESPN changed their
API format and adjusted andpoints to account for the end of the 2023 NFL season.
I hope to work with CRAN to get the package published again before the 2024
season, but it may not be possible.

The most recent development version can always be installed from [GitHub][gh]:

```{r remote, eval=FALSE}
# install.packages("remotes")
remotes::install_github("k5cents/fflr")
```

## Usage

```{r library-fflr}
library(fflr)
packageVersion("fflr")
```

Data is only available for public leagues. See [this help page][help] on how to
make a private league public

Functions require a unique `leagueId`, which can be found in any ESPN page URL.

https://fantasy.espn.com/football/league?leagueId=42654852

Use `ffl_id()` to set a default `fflr.leagueId` option. Your `.Rprofile` file
can [set this option on startup][rprof].

```{r rm-opt, echo=FALSE}
options(fflr.leagueId = NULL)
```

```{r ffl-id, message=TRUE}
ffl_id(leagueId = "42654852")
```

The `leagueId` argument defaults to `ffl_id()` and can be omitted once set.

```{r league-teams}
league_info()
league_teams()
```

The `scoringPeriodId` argument can be used to get data from past weeks.

```{r team-roster}
all_rost <- team_roster(scoringPeriodId = 1)
all_rost$CHI[, 5:13][-7]
```

There are included objects for NFL teams and players.

```{r nfl-players}
nfl_teams
```

> [!NOTE]
> The fflr project is released with a [Contributor Code of Conduct][coc]. By
contributing, you agree to abide by its terms.

[life_badge]: https://img.shields.io/badge/lifecycle-stable-brightgreen.svg
[life_link]: https://lifecycle.r-lib.org/articles/stages.html#stable
[cran_badge]: https://www.r-pkg.org/badges/version/fflr
[cran_link]: https://CRAN.R-project.org/package=fflr
[ga_badge]: https://github.com/k5cents/fflr/workflows/R-CMD-check/badge.svg
[ga_link]: https://github.com/k5cents/fflr/actions
[cov_badge]: https://codecov.io/gh/k5cents/fflr/graph/badge.svg?token=CMz6DIxJdH
[cov_link]: https://app.codecov.io/gh/k5cents/fflr?branch=master
[dl_badge]: https://cranlogs.r-pkg.org/badges/grand-total/fflr
[api]: https://lm-api-reads.fantasy.espn.com/apis/v3/games/ffl/
[iss]: https://github.com/k5cents/fflr/issues
[cran]: https://cran.r-project.org/package=fflr
[gh]: https://github.com/k5cents/fflr
[coc]: https://k5cents.github.io/fflr/CODE_OF_CONDUCT.html
[help]: https://web.archive.org/web/20211105212446/https://support.espn.com/hc/en-us/articles/360000064451-Making-a-Private-League-Viewable-to-the-Public
[rprof]: https://stat.ethz.ch/R-manual/R-devel/library/base/html/Startup.html