-
Notifications
You must be signed in to change notification settings - Fork 1
2.3 Tidy Eval
Ian Lyttle edited this page Jun 12, 2022
·
5 revisions
No files to be templated in.
- exercise:
-
R/get-matches.R
:- add
...
to formals ofuss_get_matches()
- use
...
indplyr::filter()
for results - add to documentation (
#' @inheritParams dplyr::filter
) - add to description in documentation
- add example
- add
-
tests/testthat/test-get-matches.R
:- test
...
works usingdplyr::filter()
- test
-
- we can pass
dplyr::filter()
expressions touss_get_matches()
, it will filter the results. -
R CMD CHECK
will be happy.
Template in files:
R/teams-matches.R
tests/testthat/test-teams-matches.R
- walk through code, tests
usethis::use_import_from("rlang", ".env")
- in
make_teams_matches()
:
at_home <- FALSE
teams_matches_visitor <-
data_matches |>
dplyr::rename(
team = "visitor",
opponent = "home",
goals_against = "goals_home",
goals_for = "goals_visitor"
) |>
dplyr::mutate(at_home = .env$at_home)
- we have some contrived code
-
R CMD CHECK
will be happy.
No files to be templated in.
- in
make_teams_matches()
:
# do this also with teams_matches_home
teams_matches_visitor <-
data_matches |>
dplyr::rename(!!!rename_visitor()) |>
dplyr::mutate(at_home = .env$at_home)
- we have cleaner code
-
R CMD CHECK
will be happy.
No files to be templated in.
usethis::use_import_from("rlang", ":=")
- in
make_teams_matches()
:
name_of_at_home <- "at_home"
at_home <- FALSE
teams_matches_visitor <-
data_matches |>
dplyr::rename(!!!rename_visitor()) |>
dplyr::mutate("{name_of_at_home}" := .env$at_home)
- we have some very contrived code
-
R CMD CHECK
will be happy.
No files to be templated in.
In make_teams_matches()
:
- discuss use of
dplyr::select()
anddplyr::all_of()
- add
dplyr::arrange()
step - rerun tests
- accept change in snapshot
result <-
teams_matches_home |>
dplyr::bind_rows(teams_matches_visitor) |>
dplyr::select(dplyr::all_of(cols_teams_matches())) |>
dplyr::arrange(
dplyr::across(
dplyr::all_of(
c("country", "tier", "season", "team", "date")
)
)
)
- We get
-
R CMD CHECK
will be happy.
Template in files:
R/points.R
R/seasons.R
tests/testthat/test-points.R
tests/testthat/test-seasons.R
- walk through code, emphasizing use of function as an argument
- add new function,
uss_make_seasons_final()
:
- add minimal roxygen at top
- change
mutate()
tosummarise()
- add treatment for
date
- change
cumsum()
tosum()
- we have three new exported functions:
uss_points()
,uss_make_seasons_cumulative()
,uss_make_seasons_final()
-
R CMD CHECK
will be happy.
Template in files:
R/plot.R
R/snapshot.R
tests/testthat/test-plot.R
usethis::use_package("ggplot2")
- Walk through code, esp. snapshot code.
- Add argument
aes_y = .data$wins
touss_plot_seasons_tiers()
, use{{}}
to handle. - Add documentation
#' @param aes_y ...
, example. - Uncomment tests.
- time permitting
- change one of the colors ever-so-slightly
- run the snapshot tests
- we can use an expression to specify the y-aesthetic
-
R CMD CHECK
will be happy.