New fitzRoy functions

A new set of functions to make fitzRoy a lot more consistent
fitzRoy
Author

James Day

Published

August 3, 2020

The new AFL season, with it’s condensed fixture, is proving challenging for the old little R package fitzRoy. Luckily I’ve added a couple new functions to help!

You’ll need the development version of the package.

devtools::install_github("jimmyday12/fitzRoy")
library(fitzRoy)
library(dplyr)

Fixture

I recently noticed that the get_fixture function was broken. There is unfortunately not a lot I can do with that one. The Footywire website doesn’t provide round in it’s outputs and so I’ve always just calculated this assuming that rounds begin on Thursday/Friday and finish on Sunday/Monday. That obviously doesn’t work this year!

For example, see below. The games on the 2nd August are Round 9, the games on the 3rd of August should be Round 10. The games on the 8th of August should be Round 11!

fixture <- get_fixture(season = 2020)
fixture %>% filter(Date >= lubridate::dmy("02/08/2020") & Date <= lubridate::dmy("08/08/2020"))
# A tibble: 9 × 7
  Date                Season Season.Game Round Home.Team     Away.Team     Venue
  <dttm>               <dbl>       <int> <dbl> <chr>         <chr>         <chr>
1 2020-08-02 15:35:00   2020          79     9 Gold Coast    GWS           Carr…
2 2020-08-02 16:10:00   2020          80     9 Fremantle     Collingwood   Pert…
3 2020-08-03 18:40:00   2020          81    10 Port Adelaide Footscray     Adel…
4 2020-08-04 19:10:00   2020          82    10 Richmond      Brisbane Lio… Carr…
5 2020-08-05 17:40:00   2020          83    10 Geelong       North Melbou… Gabba
6 2020-08-05 19:40:00   2020          84    10 Adelaide      Melbourne     Adel…
7 2020-08-06 17:40:00   2020          85    10 Collingwood   Sydney        Gabba
8 2020-08-06 20:10:00   2020          86    10 Gold Coast    St Kilda      Carr…
9 2020-08-07 19:50:00   2020          87    10 Essendon      GWS           Carr…

I’m going to try and get it working but in the meantime, I’ve added a new function to return the fixture from the AFL.com.au website. Obviously this is not going to be the same as the normal get_fixture function and might need some tidying of names etc, but at least it works!

The function ask you to provide a season and an optional round as arguments.

Results

The other issue I’ve found is that the AFL Tables website can sometimes take time to update after a around is over. Generally - all results come through 1-2 days after a round finishes.

get_match_results() %>%
  tail()
Warning: 'get_match_results' is deprecated.
Use 'fetch_results_afltables' instead.
See help("Deprecated")
# A tibble: 0 × 16
# … with 16 variables: Game <dbl>, Date <date>, Round <chr>, Home.Team <chr>,
#   Home.Goals <int>, Home.Behinds <int>, Home.Points <int>, Away.Team <chr>,
#   Away.Goals <int>, Away.Behinds <int>, Away.Points <int>, Venue <chr>,
#   Margin <int>, Season <dbl>, Round.Type <lgl>, Round.Number <int>

This might be an issue moving forward if there are any delays in match results. To help here, I’ve added a new function to return results from footywire.com.

Again - you can provide a season input. Optionally - you can specify the last_n_games. This is a bit clunky but again, without having round as part of the website, it’s a tricky one to scrape. For now - returning the most recent n number of matches is the easiest approach.

get_footywire_match_results(2020, last_n_matches = 10)
Warning: 'get_footywire_match_results' is deprecated.
Use 'fetch_results_footywire' instead.
See help("Deprecated")
ℹ Downloading 10 matches from Footywire
✔ Downloading 10 matches from Footywire ... done
# A tibble: 10 × 8
   Date       Time  Round             Venue      Home.…¹ Away.…² Home.…³ Away.…⁴
   <date>     <chr> <chr>             <chr>      <chr>   <chr>     <int>   <int>
 1 2020-09-21 19:15 Round 18          " Gabba"   Collin… Port A…      45      61
 2 2020-10-01 19:10 Qualifying Final  " Adelaid… Port A… Geelong      58      42
 3 2020-10-02 19:50 Qualifying Final  " Gabba"   Brisba… Richmo…      69      54
 4 2020-10-03 16:40 Elimination Final " Gabba"   St Kil… Wester…      67      64
 5 2020-10-03 18:10 Elimination Final " Optus S… West C… Collin…      75      76
 6 2020-10-09 18:50 Semi Final        " Metrico… Richmo… St Kil…      80      49
 7 2020-10-10 18:40 Semi Final        " Gabba"   Geelong Collin…     100      32
 8 2020-10-16 19:20 Preliminary Final " Adelaid… Port A… Richmo…      40      46
 9 2020-10-17 18:40 Preliminary Final " Gabba"   Brisba… Geelong      42      82
10 2020-10-24 18:30 Grand Final       " Gabba"   Richmo… Geelong      81      50
# … with abbreviated variable names ¹​Home.Team, ²​Away.Team, ³​Home.Points,
#   ⁴​Away.Points

That’s about it - let me know how you go!