Guide to function argument changes in Version 0.2.0
Ryo Nakagawara
2023-08-18
Source:vignettes/Guide_to_Version_0-2-0.Rmd
Guide_to_Version_0-2-0.Rmd
Along side the new functionality in the v0.2.0
update,
there have been a lot of changes made to existing {ggshakeR} functions
as well. This is regarding the consistency and standardization of
argument names in the package.
For guides on new functions please see:
The problem that really kicked off these changes was the fact that as
I was looking through the package’s code base, I found that we had
functions with arguments using snake_case
in some
functions, others using camelCase
, and worst of all some
functions that used both snake_case
AND
camelCase
in the argument names.
plot_passflow(pass_data, dataType, bin_size) # !!! (╯°□°)╯︵ ┻━┻
After some discussion with the other authors (Abhishek
& Harsh
), I have standardized everything to
snake_case
as well as making a number of other changes to
argument names for the sake of consistency. This does
mean some pain in the short-term, but please do know these changes are
done with user experience in mind in the long-term by lessening the
cognitive load for using the functions in the package. Some argument
names are longer now, but this shouldn’t be an issue as in RStudio you
can simply press Tab
while typing to auto-complete longer
argument names (other modern IDEs should have a similar feature as
well). An exception (hopefully a rare one as we go forward) is
binwidth
as this is essentially an argument that is being
passed on to some underlying ggplot2
function calls and we
wanted to preserve the same argument name for familiarity’s sake.
The type
arguments have also been rejigged so that the
first type
argument will always be the
type
related to the function. So for example each
plot_*()
function’s type
argument will specify
the plot type, then other arguments for the
type
of other things will have their own prefix such as
data_type
and so on. Another QOL change was to make the
data
argument be standardized across all
functions so you don’t have to figure out whether it’s
event_data
or pass_data
or
sonarData
or even simply data
… it’s
all just data
now.
Some arguments have changed their order in the functions, to learn
about why function order is important, check out Function
arguments section in ‘Advanced R’. The functions in {ggshakeR}
follows R function conventions by having the data
argument
come first, then usually a type
argument, then the rest in
an order we think makes sense.
Listed below are the changes made for version 0.2.0
to
previously existing functions:
calculate_threat()
calculate_threat(data, type)
-
data
: changed fromevent_data
-
type
: changed fromdataType
plot_heatmap()
plot_heatmap(data, type, data_type, binwidth, theme)
-
data
: changed fromevent_data
-
type
: specifically refers to the plot type whiledata_type
(below) allows you to specify the data type (StatsBomb
,Opta
, etc.) -
data_type
: changed fromdataType
-
binwidth
: changed frombin
, now the same argument name as the underlying call togeom_bin2d()
-
theme
: moved to be the last argument
plot_pass()
plot_pass(data,
type, progressive_pass,
cross, shot, switch, outcome,
theme)
-
data
: changed frompass_data
-
progressive_pass
: changed fromprog
-
type
: changed fromplot_type
, specifically refers to plot type as it is aplot_*()
function -
data_type
: changed fromdataType
plot_passflow()
plot_passflow(data, data_type, binwidth)
-
data
: changed frompass_data
-
data_type
: moved to come after thedata
argument -
binwidth
: changed frombin_size
, now the same argument name as the underlying call togeom_bin2d()
plot_pizza()
plot_pizza(data, type, template,
color_possession, color_attack, color_defense, color_compare,
player_1, player_2,
season, season_player_1, season_player_2,
theme)
-
color_possession
: changed fromcolor_poss
-
color_attack
: changed fromcolor_att
-
color_defense
: changed fromcolor_def
plot_scatter()
plot_scatter(data, x, y, label,
set_size_num, set_size_var,
set_color_num, set_color_var,
title, title_size,
subtitle, subtitle_size,
caption, caption_size,
theme)
-
x
: changed fromscatter_x
-
y
: changed fromscatter_y
-
label
: changed fromscatter_label
-
title
: changed fromscatter_title
-
subtitle
: changed fromscatter_subtitle
-
subtitle_size
: changed fromsubt_size
-
caption
: changed fromscatter_cap
-
caption_size
: changed fromcap_size
-
theme
: moved to the very end of the argument order
plot_shot()
plot_shot(data, type, bins, highlight_goals, average_location)
-
bins
: changed frombin_size
, now the same argument name as the underlying call togeom_hex()
-
average_location
: changed fromavg_loc
plot_trendline()
plot_trendline(data, team, color_xg, color_xga, rolling_average, theme)
-
color_xg
: changed fromcolour_xg
-
color_xga
: changed fromcolour_xga
-
rolling_average
: changed fromroll_avg
plot_timeline()
plot_timeline(data, match_year,
team_home, team_away,
color_home, color_away, theme)
-
color_home
: changed fromhome_color
-
color_away
: changed fromaway_color
Installing previous versions of the package
For those who are not ready to fully commit to these changes (because you have a large script with {ggshakeR} functions or whatever) but have accidentally installed the new version, fear not as you can go back and install a prior version of the package.
## Install previous 0.1.2 version
devtools::install_github("abhiamishra/ggshakeR@0.1.2")
Do note that the changes listed in this vignette are permanent and will be the standard going forward. So please take the time to read this vignette and the documentation carefully so that you can transition over to the new argument syntax and make use of the new functionality that version 0.2.0 (and beyond!) provides.