Skip to content

Commit 893a52f

Browse files
dajmcdondsweber2
authored andcommitted
style: fu
1 parent e049766 commit 893a52f

6 files changed

+23
-19
lines changed

R/layer_residual_quantiles.R

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,10 +126,11 @@ slather.layer_residual_quantiles <-
126126

127127
r <- r %>%
128128
summarize(dstn = quantile_pred(matrix(quantile(
129-
c(.resid, s * .resid), probs = object$quantile_levels, na.rm = TRUE
129+
c(.resid, s * .resid),
130+
probs = object$quantile_levels, na.rm = TRUE
130131
), nrow = 1), quantile_levels = object$quantile_levels))
131132
# Check for NA
132-
if (anyNA(as.matrix(r$dstn))) {
133+
if (anyNA(as.matrix(r$dstn))) {
133134
cli_abort(c(
134135
"Residual quantiles could not be calculated due to missing residuals.",
135136
i = "This may be due to `n_train` < `ahead` in your {.cls epi_recipe}."

R/quantile_pred-methods.R

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ quantile_internal <- function(x, tau_out, middle) {
133133
# short circuit if we aren't actually extrapolating
134134
# matches to ~15 decimals
135135
if (all(tau_out %in% tau) && !anyNA(qvals)) {
136-
return(qvals[ , match(tau_out, tau), drop = FALSE])
136+
return(qvals[, match(tau_out, tau), drop = FALSE])
137137
}
138138
if (length(tau) < 2) {
139139
cli_abort(paste(
@@ -152,7 +152,9 @@ quantile_internal <- function(x, tau_out, middle) {
152152
extrapolate_quantiles_single <- function(qvals, tau, tau_out, middle) {
153153
qvals_out <- rep(NA, length(tau_out))
154154
good <- !is.na(qvals)
155-
if (!any(good)) return(qvals_out)
155+
if (!any(good)) {
156+
return(qvals_out)
157+
}
156158
qvals <- qvals[good]
157159
tau <- tau[good]
158160

@@ -169,21 +171,22 @@ extrapolate_quantiles_single <- function(qvals, tau, tau_out, middle) {
169171

170172
if (middle == "cubic") {
171173
method <- "cubic"
172-
result <- tryCatch({
173-
Q <- stats::splinefun(tau, qvals, method = "hyman")
174-
quartiles <- Q(c(.25, .5, .75))
175-
},
176-
error = function(e) {
177-
return(NA)
178-
})
174+
result <- tryCatch(
175+
{
176+
Q <- stats::splinefun(tau, qvals, method = "hyman")
177+
quartiles <- Q(c(.25, .5, .75))
178+
},
179+
error = function(e) {
180+
return(NA)
181+
}
182+
)
179183
}
180184
if (middle == "linear" || any(is.na(result))) {
181185
method <- "linear"
182186
quartiles <- stats::approx(tau, qvals, c(.25, .5, .75))$y
183187
}
184188
if (any(indm)) {
185-
qvals_out[indm] <- switch(
186-
method,
189+
qvals_out[indm] <- switch(method,
187190
linear = stats::approx(tau, qvals, tau_out[indm])$y,
188191
cubic = Q(tau_out[indm])
189192
)

tests/testthat/test-pivot_quantiles.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,13 @@ test_that("quantile pivotting longer behaves", {
4040
expect_length(pivot_quantiles_longer(tib, d1), 4L)
4141
expect_identical(nrow(pivot_quantiles_longer(tib, d1)), 6L)
4242
expect_identical(pivot_quantiles_longer(tib, d1)$d1_value, c(1:3, 2:4))
43-
4443
})
4544

4645
test_that("nested_quantiles is deprecated, but works where possible", {
4746
expect_snapshot(d <- dist_quantiles(list(1:4, 2:5), 1:4 / 5))
4847
expect_snapshot(o <- nested_quantiles(d))
4948
res <- as_tibble(hardhat::quantile_pred(
50-
matrix(c(1:4, 2:5), nrow = 2, byrow = TRUE), 1:4 / 5)
51-
)
49+
matrix(c(1:4, 2:5), nrow = 2, byrow = TRUE), 1:4 / 5
50+
))
5251
expect_identical(o |> mutate(.row = dplyr::row_number()) |> unnest(data), res)
5352
})

tests/testthat/test-quantile_pred.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ test_that("unary math works on quantiles", {
7878
1:4 / 5
7979
)
8080
expect_identical(log(dstn), dstn2)
81-
8281
})
8382

8483
test_that("arithmetic works on quantiles", {

tests/testthat/test-step_adjust_latency.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,8 @@ test_that("epi_adjust_latency extends multiple aheads", {
243243
expect_error(
244244
expect_warning(
245245
fit3 <- fit(epi_wf, data = x),
246-
class = "epipredict__prep.step_latency__very_large_latency"),
246+
class = "epipredict__prep.step_latency__very_large_latency"
247+
),
247248
class = "simpleError"
248249
)
249250
# real date example

tests/testthat/test-wis-quantile_pred.R

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ test_that("wis dispatches and produces the correct values", {
5151
))
5252
expect_true(is.na(
5353
weighted_interval_score(
54-
quantile_pred(rbind(1:4), 1:4 / 5), 2.5, 1:9 / 10, na_handling = "fail"
54+
quantile_pred(rbind(1:4), 1:4 / 5), 2.5, 1:9 / 10,
55+
na_handling = "fail"
5556
)
5657
))
5758
})

0 commit comments

Comments
 (0)