Skip to content

Commit

Permalink
remove many library() calls in test-*.R files
Browse files Browse the repository at this point in the history
  • Loading branch information
EmilHvitfeldt committed Jul 18, 2023
1 parent 7421da1 commit 83c6282
Show file tree
Hide file tree
Showing 57 changed files with 32 additions and 106 deletions.
1 change: 0 additions & 1 deletion tests/testthat/test-BoxCox.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(rlang)

n <- 20
set.seed(1)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-arrange.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

# ------------------------------------------------------------------------------

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-basics.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
library(testthat)
library(tibble)
library(recipes)

skip_if_not_installed("modeldata")
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-bs.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
library(testthat)
library(recipes)
library(splines)

skip_if_not_installed("modeldata")
data(biomass, package = "modeldata")

Expand All @@ -21,8 +21,8 @@ test_that("correct basis functions", {
with_bs_pred_tr <- bake(with_bs, new_data = biomass_tr)
with_bs_pred_te <- bake(with_bs, new_data = biomass_te)

carbon_bs_tr_exp <- bs(biomass_tr$carbon, df = 5, degree = 2)
hydrogen_bs_tr_exp <- bs(biomass_tr$hydrogen, df = 5, degree = 2)
carbon_bs_tr_exp <- splines::bs(biomass_tr$carbon, df = 5, degree = 2)
hydrogen_bs_tr_exp <- splines::bs(biomass_tr$hydrogen, df = 5, degree = 2)
carbon_bs_te_exp <- predict(carbon_bs_tr_exp, biomass_te$carbon)
hydrogen_bs_te_exp <- predict(hydrogen_bs_tr_exp, biomass_te$hydrogen)

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-center.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
library(testthat)
library(rlang)
library(recipes)

skip_if_not_installed("modeldata")
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-class.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

skip_if_not_installed("modeldata")
data(Sacramento, package = "modeldata")
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-colcheck.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)
library(hardhat)

rp1 <- recipe(mtcars, cyl ~ .)
rp2 <- recipe(mtcars, cyl ~ mpg + drat)
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-column_order.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
library(testthat)
library(tibble)

skip_if_not_installed("modeldata")
data(biomass, package = "modeldata")

Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-cut.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
library(dplyr)

test_that("step_cut throws error on non-numerics", {
x <- tibble(num_var = 1:3, cat_var = c("1", "2", "3"))
expect_error(recipe(x) %>% step_cut(num_var, breaks = 2) %>% prep(), NA)
Expand Down
6 changes: 2 additions & 4 deletions tests/testthat/test-date.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
library(testthat)
library(recipes)
library(lubridate)
library(tibble)

examples <- data.frame(
Dan = ymd("2002-03-04") + days(1:10),
Stefan = ymd("2006-01-13") + days(1:10)
Dan = lubridate::ymd("2002-03-04") + lubridate::days(1:10),
Stefan = lubridate::ymd("2006-01-13") + lubridate::days(1:10)
)

examples$Dan <- as.POSIXct(examples$Dan)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-filter.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

# ------------------------------------------------------------------------------

Expand Down
6 changes: 1 addition & 5 deletions tests/testthat/test-grouped_df.R
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
library(tibble)
library(dplyr)


n <- 20
ex_dat <-
data.frame(x1 = seq(0, 1, length = n), x2 = rep(1:5, 4)) %>%
group_by(x1)
dplyr::group_by(x1)

# Test fixes for Issue #125
test_that("grouped data frames work", {
Expand Down
7 changes: 3 additions & 4 deletions tests/testthat/test-holiday.R
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
library(testthat)
library(recipes)
library(lubridate)

exp_dates <- data.frame(
date = ymd(c("2017-12-25", "2017-05-29", "2017-04-16")),
date = lubridate::ymd(c("2017-12-25", "2017-05-29", "2017-04-16")),
holiday = c("ChristmasDay", "USMemorialDay", "Easter"),
stringsAsFactors = FALSE
)
test_data <- data.frame(
day = c(ymd("2017-01-01") + days(0:364), NA),
day = c(lubridate::ymd("2017-01-01") + lubridate::days(0:364), NA),
stringsAsFactors = FALSE
)

Expand Down Expand Up @@ -37,7 +36,7 @@ test_that("Date class", {
)
expect_equal(
holiday_ind$day[is.na(test_data$day)],
NA_Date_
lubridate::NA_Date_
)
expect_equal(
holiday_ind$day_ChristmasDay[is.na(test_data$day)],
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-hyperbolic.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library(testthat)
library(recipes)
library(tibble)


n <- 20
set.seed(1)
Expand Down
8 changes: 3 additions & 5 deletions tests/testthat/test-impute_bag.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
library(testthat)
library(ipred)
library(rpart)
library(recipes)

skip_if_not_installed("modeldata")
Expand Down Expand Up @@ -30,9 +28,9 @@ test_that("imputation models", {
)
for (i in seq_along(carb_samps)) {
carb_data <- biomass[carb_samps[[i]], c("carbon", "hydrogen", "oxygen")]
carb_mod <- rpart(carbon ~ .,
carb_mod <- rpart::rpart(carbon ~ .,
data = carb_data,
control = rpart.control(xval = 0)
control = rpart::rpart.control(xval = 0)
)
expect_equal(
carb_mod$splits,
Expand All @@ -50,7 +48,7 @@ test_that("imputation models", {
## make sure we get the same trees given the same random samples
for (i in seq_along(fac_samps)) {
fac_data <- biomass[fac_samps[[i]], c("fac", "hydrogen", "oxygen")]
fac_mod <- rpart(fac ~ ., data = fac_data, control = fac_ctrl)
fac_mod <- rpart::rpart(fac ~ ., data = fac_data, control = fac_ctrl)
expect_equal(
fac_mod$splits,
imputed_trained$steps[[1]]$models[["fac"]]$mtrees[[i]]$btree$splits
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-impute_knn.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library(testthat)
library(gower)
library(recipes)
library(dplyr)
skip_if_not_installed("modeldata")
data(biomass, package = "modeldata")

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-impute_lower.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

skip_if_not_installed("modeldata")
data(biomass, package = "modeldata")
Expand Down
5 changes: 1 addition & 4 deletions tests/testthat/test-impute_roll.R
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
library(testthat)
library(recipes)
library(dplyr)
library(lubridate)


set.seed(145)
example_data <-
data.frame(
day = ymd("2012-06-07") + days(1:12),
day = lubridate::ymd("2012-06-07") + lubridate::days(1:12),
x1 = round(runif(12), 2),
x2 = round(runif(12), 2),
x3 = round(runif(12), 2)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-indicate_na.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(tidyr)

train <-
tibble::tibble(
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-intercept.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(tibble)

ex_dat <- tibble(
cat = factor(rep(c("A", "B"), each = 5)),
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-inverse.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(tibble)

n <- 20
set.seed(1)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-invlogit.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(tibble)

n <- 20
set.seed(12)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-lag.R
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
library(dplyr)
library(testthat)
library(recipes)

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-list_cols.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

cmplt_ex_1 <-
tibble(
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-log.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(tibble)

n <- 20
set.seed(1)
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-logit.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

n <- 20
set.seed(12)
Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-missing.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)


set_with_na <- tibble(
a = c(1, 2, NA),
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-mutate.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

iris_rec <- recipe(~., data = iris)

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-mutate_at.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

iris_rec <- recipe(~., data = iris)

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-naomit.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(tidyr)

test_that("step_naomit on all columns", {
baked <- recipe(Ozone ~ ., data = airquality) %>%
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-nomial_types.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
library(recipes)
library(dplyr)
library(testthat)

# ----------------------------------------------------------------
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-normalize.R
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
library(testthat)
library(rlang)
library(recipes)

skip_if_not_installed("modeldata")
Expand Down
6 changes: 3 additions & 3 deletions tests/testthat/test-ns.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
library(testthat)
library(recipes)
library(splines)

skip_if_not_installed("modeldata")
data(biomass, package = "modeldata")

Expand All @@ -23,8 +23,8 @@ test_that("correct basis functions", {
with_ns_pred_tr <- bake(with_ns, new_data = biomass_tr)
with_ns_pred_te <- bake(with_ns, new_data = biomass_te)

carbon_ns_tr_exp <- ns(biomass_tr$carbon, df = 2)
hydrogen_ns_tr_exp <- ns(biomass_tr$hydrogen, df = 2)
carbon_ns_tr_exp <- splines::ns(biomass_tr$carbon, df = 2)
hydrogen_ns_tr_exp <- splines::ns(biomass_tr$hydrogen, df = 2)
carbon_ns_te_exp <- predict(carbon_ns_tr_exp, biomass_te$carbon)
hydrogen_ns_te_exp <- predict(hydrogen_ns_tr_exp, biomass_te$hydrogen)

Expand Down
3 changes: 1 addition & 2 deletions tests/testthat/test-percentile.R
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
library(testthat)
library(recipes)
library(tibble)
skip_if_not_installed("modeldata")

skip_if_not_installed("modeldata")
data(biomass, package = "modeldata")

biomass_tr <- biomass[biomass$dataset == "Training", ]
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-pls.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
library(testthat)
library(recipes)
library(dplyr)

skip_if_not_installed("modeldata")

## -----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion tests/testthat/test-pls_old.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
library(testthat)
library(recipes)
library(dplyr)

skip_if_not_installed("modeldata")

## -----------------------------------------------------------------------------
Expand Down
7 changes: 2 additions & 5 deletions tests/testthat/test-poly_bernstein.R
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
library(testthat)
library(recipes)
library(splines)

skip_if_not_installed("modeldata")

data(biomass, package = "modeldata")

# ------------------------------------------------------------------------------

test_that("correct nonnegative functions", {
skip_if_not_installed("splines2")
library(splines2)

biomass_tr <- biomass[biomass$dataset == "Training", ]
biomass_te <- biomass[biomass$dataset == "Testing", ]
Expand All @@ -27,8 +24,8 @@ test_that("correct nonnegative functions", {
with_ns_pred_tr <- bake(with_ns, new_data = biomass_tr)
with_ns_pred_te <- bake(with_ns, new_data = biomass_te)

carbon_ns_tr_exp <- bernsteinPoly(biomass_tr$carbon, degree = 5)
hydrogen_ns_tr_exp <- bernsteinPoly(biomass_tr$hydrogen, degree = 5)
carbon_ns_tr_exp <- splines2::bernsteinPoly(biomass_tr$carbon, degree = 5)
hydrogen_ns_tr_exp <- splines2::bernsteinPoly(biomass_tr$hydrogen, degree = 5)
carbon_ns_te_exp <- predict(carbon_ns_tr_exp, biomass_te$carbon)
hydrogen_ns_te_exp <- predict(hydrogen_ns_tr_exp, biomass_te$hydrogen)

Expand Down
2 changes: 0 additions & 2 deletions tests/testthat/test-ratio.R
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
library(testthat)
library(recipes)
library(tibble)


n <- 20
ex_dat <- data.frame(
Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-rename.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

iris_rec <- recipe(~., data = iris)

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-rename_at.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(dplyr)

iris_rec <- recipe(~., data = iris)

Expand Down
1 change: 0 additions & 1 deletion tests/testthat/test-rm.R
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
library(testthat)
library(recipes)
library(tibble)

test_that("basics", {
n <- 20
Expand Down
Loading

0 comments on commit 83c6282

Please sign in to comment.