Skip to content

Commit

Permalink
Merge branch 'main' into r-cmd-check-hard
Browse files Browse the repository at this point in the history
  • Loading branch information
topepo authored Oct 22, 2024
2 parents c3ba770 + 92ad391 commit fb7ec56
Show file tree
Hide file tree
Showing 24 changed files with 782 additions and 300 deletions.
24 changes: 24 additions & 0 deletions tests/testthat/_snaps/constructor.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,27 @@
Error in `new_model()`:
! `blueprint` must be a <hardhat_blueprint>, not the number 1.

# `new_scalar()` must have elements

Code
new_scalar(list())
Condition
Error in `check_elems()`:
! `elems` must be a list of length 1 or greater.

# `new_scalar()` must have unique names

Code
new_scalar(list(x = 1, x = 2))
Condition
Error in `check_elems()`:
! `elems` must have unique names.

# `new_scalar()` must have no extra attributes

Code
new_scalar(x)
Condition
Error in `check_elems()`:
! `elems` must have no attributes (apart from names).

64 changes: 64 additions & 0 deletions tests/testthat/_snaps/forge-formula.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,67 @@
# asking for the outcome when it isn't there fails

Code
forge(example_train2, x1$blueprint, outcomes = TRUE)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'fac_1'.

---

Code
forge(example_train2, x2$blueprint, outcomes = TRUE)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'fac_1'.

# new_data can only be a data frame / matrix

Code
forge("hi", x1$blueprint)
Condition
Error in `forge()`:
! The class of `new_data`, 'character', is not recognized.

---

Code
forge("hi", x2$blueprint)
Condition
Error in `forge()`:
! The class of `new_data`, 'character', is not recognized.

# missing predictor columns fail appropriately

Code
forge(example_train[, 1, drop = FALSE], x1$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'num_2'.

---

Code
forge(example_train[, 1, drop = FALSE], x2$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'num_2'.

---

Code
forge(example_train[, 3, drop = FALSE], x1$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'num_1', 'num_2'.

---

Code
forge(example_train[, 3, drop = FALSE], x2$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'num_1', 'num_2'.

# novel predictor levels are caught

Code
Expand Down
32 changes: 32 additions & 0 deletions tests/testthat/_snaps/forge-recipe.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
# asking for the outcome when it isn't there fails

Code
forge(iris2, x1$blueprint, outcomes = TRUE)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'Species'.

---

Code
forge(iris2, x2$blueprint, outcomes = TRUE)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'Species'.

# missing predictor columns fail appropriately

Code
forge(iris[, 1, drop = FALSE], x$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'Sepal.Width'.

---

Code
forge(iris[, 3, drop = FALSE], x$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'Sepal.Length', 'Sepal.Width'.

# novel predictor levels are caught

Code
Expand Down
76 changes: 76 additions & 0 deletions tests/testthat/_snaps/forge-xy.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,79 @@
# asking for the outcome is special cased for vector `y` values

Code
forge(iris, x1$blueprint, outcomes = TRUE)
Condition
Error in `validate_missing_name_isnt_.outcome()`:
! The following required columns are missing: '.outcome'.
(This indicates that `mold()` was called with a vector for `y`. When this is the case, and the outcome columns are requested in `forge()`, `new_data` must include a column with the automatically generated name, '.outcome', containing the outcome.)

---

Code
forge(iris, x2$blueprint, outcomes = TRUE)
Condition
Error in `validate_missing_name_isnt_.outcome()`:
! The following required columns are missing: '.outcome'.
(This indicates that `mold()` was called with a vector for `y`. When this is the case, and the outcome columns are requested in `forge()`, `new_data` must include a column with the automatically generated name, '.outcome', containing the outcome.)

# new_data can only be a data frame / matrix

Code
forge("hi", x1$blueprint)
Condition
Error in `forge()`:
! The class of `new_data`, 'character', is not recognized.

---

Code
forge("hi", x2$blueprint)
Condition
Error in `forge()`:
! The class of `new_data`, 'character', is not recognized.

---

Code
forge("hi", x3$blueprint)
Condition
Error in `forge()`:
! The class of `new_data`, 'character', is not recognized.

# missing predictor columns fail appropriately

Code
forge(iris[, 1, drop = FALSE], x1$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'Sepal.Width'.

---

Code
forge(iris[, 1, drop = FALSE], x2$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'Sepal.Width'.

---

Code
forge(iris[, 3, drop = FALSE], x1$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'Sepal.Length', 'Sepal.Width'.

---

Code
forge(iris[, 3, drop = FALSE], x2$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'Sepal.Length', 'Sepal.Width'.

# novel predictor levels are caught

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/levels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Can extract levels from an outcome

Code
get_outcome_levels("a")
Condition
Error in `standardize()`:
! `y` is of unknown type 'character'.

16 changes: 16 additions & 0 deletions tests/testthat/_snaps/model-offset.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Only numeric columns can be offsets

Code
mold(~ Sepal.Width + offset(Species), iris)
Condition
Error in `model_offset()`:
! Column, 'offset(Species)', is tagged as an offset, but is not numeric. All offsets must be numeric.

# offset columns are stored as predictors

Code
forge(iris2, x$blueprint)
Condition
Error in `validate_column_names()`:
! The following required columns are missing: 'Sepal.Length'.

105 changes: 105 additions & 0 deletions tests/testthat/_snaps/mold-formula.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,79 @@
! Functions involving factors or characters have been detected on the RHS of `formula`. These are not allowed when `indicators = "none"`.
i Functions involving factors were detected for "fac_1" in `paste0(fac_1)`.

# formulas with non-existent columns are caught

Code
mold(fac_1 ~ y + z, example_train)
Condition
Error in `get_all_predictors()`:
! The following predictors were not found in `data`: 'y', 'z'.

---

Code
mold(fac_1 ~ y + z, example_train, blueprint = bp)
Condition
Error in `get_all_predictors()`:
! The following predictors were not found in `data`: 'y', 'z'.

---

Code
mold(y + z ~ fac_1, example_train)
Condition
Error in `get_all_outcomes()`:
! The following outcomes were not found in `data`: 'y', 'z'.

---

Code
mold(y + z ~ fac_1, example_train, blueprint = bp)
Condition
Error in `get_all_outcomes()`:
! The following outcomes were not found in `data`: 'y', 'z'.

# global environment variables cannot be used

Code
y <- 1
mold(fac_1 ~ y, example_train)
Condition
Error in `get_all_predictors()`:
! The following predictors were not found in `data`: 'y'.

# cannot manually remove intercept in the formula itself

Code
mold(fac_1 ~ y + 0, example_train)
Condition
Error in `mold_formula_default_clean()`:
! `formula` must not contain the intercept removal term: `+ 0` or `0 +`.

---

Code
mold(fac_1 ~ y + 0, example_train, blueprint = bp)
Condition
Error in `mold_formula_default_clean()`:
! `formula` must not contain the intercept removal term: `+ 0` or `0 +`.

---

Code
mold(fac_1 ~ 0 + y, example_train)
Condition
Error in `mold_formula_default_clean()`:
! `formula` must not contain the intercept removal term: `+ 0` or `0 +`.

---

Code
mold(fac_1 ~ y - 1, example_train)
Condition
Error in `mold_formula_default_clean()`:
! `formula` must not contain the intercept removal term: `- 1`.

# RHS with _only_ intercept related terms are caught

Code
Expand Down Expand Up @@ -169,6 +242,22 @@
Error in `mold_formula_default_clean()`:
! `formula` must not contain the intercept removal term, `0`.

# `data` is validated

Code
mold(fac_1 ~ num_2, 1)
Condition
Error in `mold_formula_default_clean()`:
! `data` must be a data frame or a matrix, not the number 1.

---

Code
mold(fac_1 ~ num_2, 1, blueprint = bp)
Condition
Error in `mold_formula_default_clean()`:
! `data` must be a data frame or a matrix, not the number 1.

# LHS of the formula cannot contain interactions

Code
Expand Down Expand Up @@ -223,6 +312,22 @@
! Interaction terms can't be specified on the LHS of `formula`.
i The following interaction term was found: `num_1/num_2`.

# `.` notation fails on the LHS

Code
mold(. ~ fac_1, example_train)
Condition
Error in `get_all_outcomes()`:
! The left hand side of the formula cannot contain `.`

---

Code
mold(. ~ fac_1, example_train, blueprint = bp)
Condition
Error in `get_all_outcomes()`:
! The left hand side of the formula cannot contain `.`

# `blueprint` is validated

Code
Expand Down
8 changes: 8 additions & 0 deletions tests/testthat/_snaps/mold-recipe.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# `data` is validated

Code
mold(recipes::recipe(Species ~ Sepal.Length, data = iris), 1)
Condition
Error in `mold_recipe_default_clean()`:
! `data` must be a data frame or a matrix, not the number 1.

Loading

0 comments on commit fb7ec56

Please sign in to comment.