Skip to content

Commit

Permalink
styler
Browse files Browse the repository at this point in the history
  • Loading branch information
dajmcdon committed Jul 24, 2024
1 parent d15f800 commit fc0e99c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 12 deletions.
4 changes: 3 additions & 1 deletion R/get_test_data.R
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ pad_to_end <- function(x, groups, end_date) {
}

Seq <- function(from, to, by) {
if (from > to) return(NULL)
if (from > to) {
return(NULL)
}
seq(from = from, to = to, by = by)
}
18 changes: 8 additions & 10 deletions R/step_epi_slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,6 @@ step_epi_slide_new <-

#' @export
prep.step_epi_slide <- function(x, training, info = NULL, ...) {

col_names <- recipes::recipes_eval_select(x$terms, data = training, info = info)

check_type(training[, col_names], types = c("double", "integer"))
Expand All @@ -164,7 +163,6 @@ prep.step_epi_slide <- function(x, training, info = NULL, ...) {

#' @export
bake.step_epi_slide <- function(object, new_data, ...) {

recipes::check_new_data(names(object$columns), object, new_data)
col_names <- object$columns
name_prefix <- paste0(object$prefix, object$f_name, "_")
Expand All @@ -176,7 +174,8 @@ bake.step_epi_slide <- function(object, new_data, ...) {
nms <- new_data_names[intersection]
cli_abort(
c("Name collision occured. The following variable names already exist:",
`*` = "{.var {nms}}"),
`*` = "{.var {nms}}"
),
call = caller_env()
)
}
Expand All @@ -191,7 +190,8 @@ bake.step_epi_slide <- function(object, new_data, ...) {
dplyr::across(
dplyr::all_of(object$columns),
~ slider::slide_index_vec(
.x, .i = time_value,
.x,
.i = time_value,
object$.f, .before = object$before, .after = object$after
)
)
Expand Down Expand Up @@ -270,7 +270,7 @@ validate_slide_fun <- function(.f) {
try_period <- function(x) {
err <- is.na(x)
if (!err) {
if (is.numeric(x) ) {
if (is.numeric(x)) {
err <- !rlang::is_integerish(x) || x < 0
} else {
x <- lubridate::as.period(x)
Expand All @@ -279,12 +279,10 @@ try_period <- function(x) {
}
if (err) {
cli_abort(paste(
'The value supplied to `before` or `after` must be a non-negative integer',
'a {.cls lubridate::period} or a character scalar that can be coerced',
"The value supplied to `before` or `after` must be a non-negative integer",
"a {.cls lubridate::period} or a character scalar that can be coerced",
'as a {.cls lubridate::period}, e.g., `"1 week"`.'
),
)
), )
}
x
}

1 change: 0 additions & 1 deletion tests/testthat/test-step_epi_slide.R
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ rolled_after <- edf %>%


test_that("epi_slide handles classed before/after", {

baseline <- r %>%
step_epi_slide(value, .f = mean, before = 3L) %>%
prep(edf) %>%
Expand Down

0 comments on commit fc0e99c

Please sign in to comment.