Skip to content

Commit

Permalink
better control about the variables that should round
Browse files Browse the repository at this point in the history
also round to 3 significant digits because tests failed on Mac in the 4th digit
  • Loading branch information
mrcaseb committed Jun 26, 2024
1 parent ec4d79c commit 2c79f02
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions tests/testthat/helpers.R
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,27 @@ strip_nflverse_attributes <- function(df){
df
}

round_double_to_digits <- function(df, digits = 4){
dplyr::mutate_if(df, is.double, formatC, digits = digits, format = "fg")
round_double_to_digits <- function(df, digits = 3){
dplyr::mutate(df, dplyr::across(
.cols = relevant_variables(),
.fns = function(vec){
formatC(vec, digits = digits, format = "fg") %>%
as.numeric() %>%
suppressWarnings()
}
))
}

relevant_variables <- function(){
c(
tidyselect::any_of(c(
"no_score_prob", "opp_fg_prob", "opp_safety_prob", "opp_td_prob", "fg_prob",
"safety_prob", "td_prob", "ep", "cp", "cpoe", "pass_oe"
)),
tidyselect::ends_with("epa"),
tidyselect::ends_with("wp"),
tidyselect::ends_with("wp_post"),
tidyselect::ends_with("wpa"),
tidyselect::starts_with("xyac")
)
}

0 comments on commit 2c79f02

Please sign in to comment.