Skip to content

Commit 845c1a9

Browse files
committed
run styler
1 parent e6e60cd commit 845c1a9

7 files changed

+49
-36
lines changed

R/epi_workflow.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ predict.epi_workflow <- function(object, new_data, ...) {
253253
if (!workflows::is_trained_workflow(object)) {
254254
cli::cli_abort(c(
255255
"Can't predict on an untrained epi_workflow.",
256-
i = "Do you need to call `fit()`?"
256+
i = "Do you need to call `fit()`?"
257257
))
258258
}
259259
components <- list()

R/layer_add_forecast_date.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ slather.layer_add_forecast_date <- function(object, components, workflow, new_da
9797
expected_time_type <- attr(
9898
workflows::extract_preprocessor(workflow)$template, "metadata"
9999
)$time_type
100-
if (expected_time_type == "week") expected_time_type = "day"
100+
if (expected_time_type == "week") expected_time_type <- "day"
101101
check <- validate_date(object$forecast_date, expected_time_type)
102102

103103
if (!check$ok) {

R/layer_add_target_date.R

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ slather.layer_add_target_date <- function(object, components, workflow, new_data
8787
expected_time_type <- attr(
8888
workflows::extract_preprocessor(workflow)$template, "metadata"
8989
)$time_type
90-
if (expected_time_type == "week") expected_time_type = "day"
90+
if (expected_time_type == "week") expected_time_type <- "day"
9191

9292
if (!is.null(object$target_date)) {
9393
check <- validate_date(object$target_date, expected_time_type)
@@ -101,10 +101,9 @@ slather.layer_add_target_date <- function(object, components, workflow, new_data
101101
target_date <- coerce_time_type(object$target_date, expected_time_type)
102102
} else if (
103103
detect_layer(the_frosting, "layer_add_forecast_date") &&
104-
!is.null(possible_fd <- extract_argument(
105-
the_frosting, "layer_add_forecast_date", "forecast_date"
106-
))) {
107-
104+
!is.null(possible_fd <- extract_argument(
105+
the_frosting, "layer_add_forecast_date", "forecast_date"
106+
))) {
108107
check <- validate_date(possible_fd, expected_time_type)
109108
if (!check$ok) {
110109
cli::cli_abort(c(
@@ -117,13 +116,13 @@ slather.layer_add_target_date <- function(object, components, workflow, new_data
117116
ahead <- extract_argument(the_recipe, "step_epi_ahead", "ahead")
118117
target_date <- forecast_date + ahead
119118
} else {
120-
max_time_value <- max(
121-
workflows::extract_preprocessor(workflow)$max_time_value,
122-
workflow$fit$meta$max_time_value,
123-
max(new_data$time_value)
124-
)
125-
ahead <- extract_argument(the_recipe, "step_epi_ahead", "ahead")
126-
target_date <- max_time_value + ahead
119+
max_time_value <- max(
120+
workflows::extract_preprocessor(workflow)$max_time_value,
121+
workflow$fit$meta$max_time_value,
122+
max(new_data$time_value)
123+
)
124+
ahead <- extract_argument(the_recipe, "step_epi_ahead", "ahead")
125+
target_date <- max_time_value + ahead
127126
}
128127

129128
components$predictions <- dplyr::bind_cols(components$predictions,

R/step_epi_shift.R

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,8 @@ step_epi_ahead <-
120120
if (missing(ahead)) {
121121
cli::cli_abort(c(
122122
"The `ahead` argument must not be empty.",
123-
i = "Did you perhaps pass an integer in `...` accidentally?"
124-
)
125-
)
123+
i = "Did you perhaps pass an integer in `...` accidentally?"
124+
))
126125
}
127126
arg_is_nonneg_int(ahead)
128127
arg_is_chr_scalar(prefix, id)

R/time_types.R

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,35 +3,53 @@ guess_time_type <- function(time_value) {
33
arg_is_scalar(time_value)
44
if (is.character(time_value)) {
55
if (nchar(time_value) <= "10") {
6-
new_time_value <- tryCatch({
7-
as.Date(time_value)
8-
}, error = function(e) NULL)
6+
new_time_value <- tryCatch(
7+
{
8+
as.Date(time_value)
9+
},
10+
error = function(e) NULL
11+
)
912
} else {
10-
new_time_value <- tryCatch({
11-
as.POSIXct(time_value)
12-
}, error = function(e) NULL)
13+
new_time_value <- tryCatch(
14+
{
15+
as.POSIXct(time_value)
16+
},
17+
error = function(e) NULL
18+
)
1319
}
1420
if (!is.null(new_time_value)) time_value <- new_time_value
1521
}
16-
if (inherits(time_value, "POSIXct")) return("day-time")
17-
if (inherits(time_value, "Date")) return("day")
18-
if (inherits(time_value, "yearweek")) return("yearweek")
19-
if (inherits(time_value, "yearmonth")) return("yearmonth")
20-
if (inherits(time_value, "yearquarter")) return("yearquarter")
22+
if (inherits(time_value, "POSIXct")) {
23+
return("day-time")
24+
}
25+
if (inherits(time_value, "Date")) {
26+
return("day")
27+
}
28+
if (inherits(time_value, "yearweek")) {
29+
return("yearweek")
30+
}
31+
if (inherits(time_value, "yearmonth")) {
32+
return("yearmonth")
33+
}
34+
if (inherits(time_value, "yearquarter")) {
35+
return("yearquarter")
36+
}
2137
if (is.numeric(time_value) && all(time_value == as.integer(time_value)) &&
22-
all(time_value >= 1582)) {
38+
all(time_value >= 1582)) {
2339
return("year")
2440
}
2541
return("custom")
2642
}
2743

2844
coerce_time_type <- function(x, target_type) {
2945
if (target_type == "year") {
30-
if (is.numeric(x)) return(as.integer(x))
31-
else return(as.POSIXlt(x)$year + 1900L)
46+
if (is.numeric(x)) {
47+
return(as.integer(x))
48+
} else {
49+
return(as.POSIXlt(x)$year + 1900L)
50+
}
3251
}
33-
switch(
34-
target_type,
52+
switch(target_type,
3553
"day-time" = as.POSIXct(x),
3654
"day" = as.Date(x),
3755
"week" = as.Date(x),

tests/testthat/test-layer_add_forecast_date.R

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,5 +104,4 @@ test_that("forecast date works for daily", {
104104
adjust_frosting(f, "layer_add_forecast_date", forecast_date = 2022L)
105105
)
106106
expect_error(predict(wf1, latest)) # wrong time type of forecast_date
107-
108107
})

tests/testthat/test-layer_add_target_date.R

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,4 @@ test_that("forecast date works for daily", {
115115
adjust_frosting(f, "layer_add_target_date", target_date = 2022L)
116116
)
117117
expect_error(predict(wf1, latest)) # wrong time type of forecast_date
118-
119118
})
120-

0 commit comments

Comments
 (0)