---
title: "Womens' AFL Stats"
author: "Oscar Lane"
date: "`r Sys.Date()`"
output: github_document
vignette: >
  %\VignetteIndexEntry{Womens' AFL Stats}
  %\VignetteEngine{knitr::rmarkdown}
  %\VignetteEncoding{UTF-8}
---

```{r setup, include = FALSE}
not_cran = identical(Sys.getenv("NOT_CRAN"), "true")
online <- !is.null(curl::nslookup("r-project.org", error = FALSE))
eval_param <- not_cran & online

knitr::opts_chunk$set(
  collapse = TRUE,
  comment = "#>",
  eval = eval_param
)
```

NOTE - The AFL website for Women's data has been taken down. This page is left for posterity however these functions no longer work. 


### Match data

```{r libraries, message=FALSE, warning=FALSE, eval=eval_param}
library(fitzRoy)
library(dplyr)
```

A good thing to check is that the cookie is working. Often this gets changed or moved and without it, the code won't work. 

```{r cookie, message = FALSE, warning = FALSE, eval=eval_param}
cookie <- get_aflw_cookie()

print(cookie)
```
Note - if this is `NULL` the rest of this Vignette won't show any outputs but the code will remain! 

```{r cookie_param, include=FALSE, eval=eval_param}
if (is.null(cookie)) {
    eval_param = FALSE
  }

```

We can use the `get_aflw_match_data()` function to retrieve match data for all
matches.

```{r fetch_match_stats, message=FALSE, warning=TRUE, eval = eval_param}
match_data <- get_aflw_match_data()
```

Note that there will be warnings if a fixture is available but no match data has
been added yet. If this is the case, make sure you don't try to request detailed
match stats for these match IDs. 

```{r show_match_stats, message=FALSE, warning=FALSE, eval = eval_param}
glimpse(match_data)
```

### Detailed stats

The `get_aflw_detailed_data()` can be used to return more detailed data than the
match data shown above. It takes a vector of match IDs as an argument. For
example, let's say we want detailed stats for the first 10 games in `match_data`
above. Then we would do:

```{r first_10, message=FALSE, warning=FALSE, eval = eval_param}
first10 <- head(match_data, 10)
first10_ids <- first10$Match.Id
first10_ids
```

```{r, eval = eval_param}
detailed <- get_aflw_detailed_data(first10_ids)
glimpse(detailed)
```

