Skip to content

Commit 5464bd1

Browse files
authored
Merge pull request #31 from kenmawer/km-pr_34_rectify_tests
Km pr 34 rectify tests
2 parents 0dbfc2e + 6fa4a5f commit 5464bd1

File tree

3 files changed

+39
-15
lines changed

3 files changed

+39
-15
lines changed

R/step_epi_naomit.R

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,24 @@
1-
#' Special NA omit step that does two steps in one
1+
#' Unified NA omission wrapper function for recipes
22
#'
3-
#' @param x Recipe to be used for omission steps
3+
#' @param recipe Recipe to be used for omission steps
44
#'
5-
#' @return Omits NA's from both predictors and outcomes and training time;
6-
#' however, only omits predictors at prediction time
5+
#' @return Omits NA's from both predictors and outcomes at training time;
6+
#' however, only omits associated predictors at prediction time to avoid
7+
#' losing data.
78
#' @export
9+
#' @examples
10+
#' tibble(geo_value = rep("place",200),
11+
#' time_value = as.Date("2021-01-01") + 0:199,
12+
#' case_rate = 1:200,
13+
#' death_rate = 1:200) %>%
14+
#' as_epi_df() %>%
15+
#' recipe() %>%
16+
#' step_epi_naomit()
817

9-
step_epi_naomit <- function(x) {
10-
x %>%
18+
19+
step_epi_naomit <- function(recipe) {
20+
stopifnot("recipe" %in% class(recipe))
21+
recipe %>%
1122
recipes::step_naomit(all_predictors()) %>%
1223
recipes::step_naomit(all_outcomes(), skip = TRUE)
1324
}

man/step_epi_naomit.Rd

Lines changed: 16 additions & 6 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/testthat/test-step_epi_naomit.R

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,21 @@ library(parsnip)
44
library(workflows)
55

66
# Random generated dataset
7-
set.seed(100)
87
x <- tibble(geo_value = rep("nowhere",200),
98
time_value = as.Date("2021-01-01") + 0:199,
10-
case_rate = rpois(100,20) + 1:200,
11-
death_rate = rpois(100,10) + 1:200) %>%
9+
case_rate = 1:200,
10+
death_rate = 1:200) %>%
1211
as_epi_df()
1312

1413
# Preparing the datasets to be used for comparison
1514
r <- epi_recipe(x) %>%
1615
step_epi_ahead(death_rate, ahead = 7) %>%
1716
step_epi_lag(death_rate, lag = c(0,7,14))
1817

18+
test_that("Argument must be a recipe", {
19+
expect_error(step_epi_naomit(x))
20+
})
21+
1922
z1 <- step_epi_naomit(r)
2023
z2 <- r %>%
2124
step_naomit(all_predictors()) %>%

0 commit comments

Comments
 (0)