fitzRoy v1.4.0 on CRAN

Author

James Day

Published

June 7, 2024

I’m pleased to announce that fitzRoy v1.4.0 has just been accepted to CRAN!

This update mostly contains bug fixes. You can read about them below.

New Features

Squiggle API is now more flexible

The function to call the Squiggle API is now more flexible and should allow for any new queries that are added to the Squiggle API to be used. Previously many of the queries and optional arguments were hardcode but these are now simply sent to the API as is, and the API will return data accordingly. You can read about the API here and provide any of the main “query” types to the first argument, with additional optional parameters being named arguments you can supply.

As a general rule

  • Invalid query types will return an error

  • Invalid optional argument types will be ignored and API data returned based on other arguments

  • Optional arguments with nonsensical values will generally return an empty data frame

Previously all of these situations returned an unhelpful error.

# Return a list of the sources, with ID's
fitzRoy::fetch_squiggle_data("sources")
ℹ Getting data from https://api.squiggle.com.au?q=sources&format=JSON
✔ Getting data from https://api.squiggle.com.au?q=sources&format=JSON [1.3s]
# A tibble: 38 × 4
   name            icon                                                 id url  
   <chr>           <chr>                                             <int> <chr>
 1 Squiggle        "/wp-content/themes/squiggle/assets/images/Squig…     1 "htt…
 2 The Arc         "/wp-content/themes/squiggle/assets/images/TheAr…     2 "htt…
 3 Figuring Footy  "/wp-content/themes/squiggle/assets/images/Figur…     3 "htt…
 4 Matter of Stats "/wp-content/themes/squiggle/assets/images/MoS.p…     4 "htt…
 5 Punters         ""                                                    5 ""   
 6 FMI             "/wp-content/themes/squiggle/assets/images/FMI.p…     6 "htt…
 7 PlusSixOne      "/wp-content/themes/squiggle/assets/images/p61.p…     7 "htt…
 8 Aggregate       ""                                                    8 "/in…
 9 Graft           "/wp-content/themes/squiggle/assets/images/Graft…     9 "htt…
10 Stattraction    "/wp-content/themes/squiggle/assets/images/statt…    10 "htt…
# … with 28 more rows
# Provide an incorrect query
fitzRoy::fetch_squiggle_data(query = "fitzRoy")
ℹ Getting data from https://api.squiggle.com.au?q=fitzRoy&format=JSON
Error in `fitzRoy::fetch_squiggle_data()`:
! API did not return any data
ℹ Did you check that the queries provided are valid?
✖ You've supplied the following queries: "q"
✖ Getting data from https://api.squiggle.com.au?q=fitzRoy&format=JSON [447ms]
# Provide an invalid optional argument
fitzRoy::fetch_squiggle_data(query = "tips", fitzRoy = TRUE, source = 1, year = 2024)
ℹ Getting data from https://api.squiggle.com.au?q=tips&fitzRoy=TRUE&source=1&ye…
✔ Getting data from https://api.squiggle.com.au?q=tips&fitzRoy=TRUE&source=1&ye…
# A tibble: 207 × 21
   date    margin tipte…¹ tip   confi…² round gameid hmargin ateam ateamid bits 
   <chr>   <chr>    <int> <chr> <chr>   <int>  <int> <chr>   <chr>   <int> <chr>
 1 2024-0… 12.52        2 Bris… 63.05       0  35701 12.52   Carl…       3 -0.4…
 2 2024-0… 5.90         8 Gold… 55.92       0  35702 5.90    Rich…      14 0.16…
 3 2024-0… 9.12         9 Grea… 59.36       0  35703 9.12    Coll…       4 0.24…
 4 2024-0… 2.34        11 Melb… 52.27       0  35700 -2.34   Melb…      11 -0.0…
 5 2024-0… 0.01         3 Carl… 50.01       1  35704 0.01    Rich…      14 0.00…
 6 2024-0… 8.44         4 Coll… 58.62       1  35705 8.44    Sydn…      16 -0.2…
 7 2024-0… 0.01         5 Esse… 50.01       1  35706 0.01    Hawt…      10 0.00…
 8 2024-0… 7.08         2 Bris… 57.16       1  35712 -7.08   Bris…       2 -0.2…
 9 2024-0… 19.85        7 Geel… 70.65       1  35708 19.85   St K…      15 0.49…
10 2024-0… 0.01         1 Adel… 50.01       1  35709 -0.01   Adel…       1 -0.0…
# … with 197 more rows, 10 more variables: hconfidence <chr>, correct <int>,
#   sourceid <int>, venue <chr>, hteam <chr>, hteamid <int>, year <int>,
#   updated <chr>, err <chr>, source <chr>, and abbreviated variable names
#   ¹​tipteamid, ²​confidence
# Provide an incorrect optional argument value
fitzRoy::fetch_squiggle_data(query = "tips", fitzRoy = TRUE, source = 1, year = 2030)
ℹ Getting data from https://api.squiggle.com.au?q=tips&fitzRoy=TRUE&source=1&ye…
✔ Getting data from https://api.squiggle.com.au?q=tips&fitzRoy=TRUE&source=1&ye…
# A tibble: 0 × 0

replace_teams now handle indigenous names

With teams starting to use indigenous names during Sir Doug Nicholls rounds, the AFL API was returning these names over the traditional team names, which was causing errors in places. Most people were handling this in their own code, or using teamIds, but where the package was using replace_names function, we’ve added a check to ensure we can match the indigenous and traditional name together.

fitzRoy::replace_teams("Narrm")
[1] "Melbourne"
fitzRoy::replace_teams("Walyalup")
[1] "Fremantle"

Bug Fixes

  • Handle “Opening Round” fixtures for a bunch of functions that were breaking

  • Fixed a bug where fetch_player_details was failing for certain teams

  • Handled situations where an ‘unused sub’ was causing issues on various Footywire functions

  • Removed some failing tests that were overkill

Enjoy!