| Title: | Testing Infrastructure for Broom Model Generics |
|---|---|
| Description: | Provides a number of testthat tests that can be used to verify that tidy(), glance() and augment() methods meet consistent specifications. This allows methods for the same generic to be spread across multiple packages, since all of those packages can make the same guarantees to users about returned objects. |
| Authors: | Alex Hayes [aut, cre] (ORCID: <https://orcid.org/0000-0002-4985-5160>), Simon Couch [aut] |
| Maintainer: | Alex Hayes <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.1.8.9000 |
| Built: | 2026-06-07 07:40:22 UTC |
| Source: | https://github.com/alexpghayes/modeltests |
Given a data frame (or tibble), and a model object, makes a character vector of acceptable columns names for augment output. This includes:
Any column names of the passed dataset
Any syntactically correct column names generated by calling
stats::model.frame() on the object in question.
acceptable_augment_colnames(object, passed_data)acceptable_augment_colnames(object, passed_data)
object |
A model object. |
passed_data |
The dataset used to create the model object. |
A vector of colnames that are acceptable in augment output.
Allowed argument names in tidiers
argument_glossaryargument_glossary
A tibble with 3 variables:
One of "glance", "augment" or "tidy".
Character name of allowed argument name.
Character description of argument use.
argument_glossaryargument_glossary
Call this function to perform tests. If a tests fails, an informative error will be thrown. Otherwise silent.
Tests when strict = FALSE:
None
Tests when strict = TRUE:
tidy_method has a conf.int argument if it has a conf.level argument.
tidy_method has a conf.level argument if it has a conf.int argument.
conf.int defaults to FALSE when present.
conf.level defaults to '0.95“ when present.
exponentiate defaults to FALSE when present.
All arguments to tidy_method are listed in the argument_glossary.
check_arguments(tidy_method, strict = TRUE)check_arguments(tidy_method, strict = TRUE)
tidy_method |
A tidying method. For example: |
strict |
Logical indicating whether the strict version of tests should be used. Defaults
to |
An invisible NULL. This function should be called for side effects, not return values.
Call this function to perform tests. If a tests fails, an informative error will be thrown. Otherwise silent.
Test when strict = FALSE:
aug(model, data = data) passes check_tibble()
aug(model, newdata = newdata) passes check_tibble()
Additional tests when strict = TRUE:
aug(model, data = data) passes check_augment_data_specification().
aug(model, newdata = newdata) passes check_augment_data_specification().
aug(model, newdata = newdata) passes check_augment_data_specification()
with add_missing = TRUE.
If aug has a newdata argument, the newdata argument takes precedence
over a data argument, i.e. calls check_augment_newdata_precedence().
aug either gives an informative error or produces a reasonable tibble,
i.e. calls check_augment_no_data().
Note that it doesn't make sense to test that aug(model, data = data)
passes check_augment_data_specification() with add_missing = TRUE. This is
because the user is already guaranteeing that data is the original dataset
used to create model.
check_augment_function(aug, model, data = NULL, newdata = NULL, strict = TRUE)check_augment_function(aug, model, data = NULL, newdata = NULL, strict = TRUE)
aug |
An augment method. For example, |
model |
A fit model object to call the augment method on. |
data |
A data frame or tibble to use when testing |
newdata |
A dataset to use to check the |
strict |
Logical indicating whether the strict version of tests should be used. Defaults
to |
An invisible NULL. This function should be called for side effects, not return values.
Call this function to perform tests. If a tests fails, an informative error will be thrown. Otherwise silent.
check_augment_newdata_precedence(aug, model, data, strict = TRUE)check_augment_newdata_precedence(aug, model, data, strict = TRUE)
aug |
An augment method. For example, |
model |
A fit model object to call the augment method on. |
data |
A data frame or tibble to use when testing |
strict |
Logical indicating whether the strict version of tests should be used. Defaults
to |
An invisible NULL. This function should be called for side effects, not return values.
Call this function to perform tests. If a tests fails, an informative error will be thrown. Otherwise silent.
Test when strict = FALSE:
None
Additional tests when strict = TRUE:
aug(model) either returns an informative error or produces output
that passes check_tibble().
If the output passes check_tibble, will issue warning when:
Augmented data is missing rows from original data.
Augmented data is missing columns from original data.
Original data has rownames but ugmented data is missing .rownames
column.
check_augment_no_data(aug, model, passed_data, strict = TRUE)check_augment_no_data(aug, model, passed_data, strict = TRUE)
aug |
An augment method. For example, |
model |
A fit model object to call the augment method on. |
passed_data |
The dataset that |
strict |
Logical indicating whether the strict version of tests should be used. Defaults
to |
An invisible NULL. This function should be called for side effects, not return values.
Check that tibble has expected dimensions.
check_dims(data, expected_rows = NULL, expected_cols = NULL)check_dims(data, expected_rows = NULL, expected_cols = NULL)
data |
A tibble or data frame. |
expected_rows |
Expected number of rows of tibble. |
expected_cols |
Expected number of columns of tibble. |
check_dims(iris, expected_rows = 150)check_dims(iris, expected_rows = 150)
Call this function to perform tests. If a tests fails, an informative error will be thrown. Otherwise silent.
Tests when strict = FALSE:
Each item passed to ... passes check_tibble()
Each item passed to ... has exactly 1 row.
Additional tests when strict = TRUE:
Column names and order agree across all elements of ....
check_glance_outputs(..., strict = TRUE)check_glance_outputs(..., strict = TRUE)
... |
Outputs returned from calls to (the same) |
strict |
Logical indicating whether the strict version of tests should be used. Defaults
to |
An invisible NULL. This function should be called for side effects, not return values.
Call this function to perform tests. If a tests fails, an informative error will be thrown. Otherwise silent.
Tests when strict = FALSE:
output is a tibble.
Additional tests when strict = TRUE:
columns are listed in the column_glossary.
check_tibble(output, method, columns = colnames(output), strict = TRUE)check_tibble(output, method, columns = colnames(output), strict = TRUE)
output |
Object returned from |
method |
One of |
columns |
The names of the columns in the output data frame. Defaults
to the column names of |
strict |
Logical indicating whether the strict version of tests should be used. Defaults
to |
Do not call directly. Helper function used by check_tidy_output(),
check_glance_outputs() and check_augment_function().
An invisible NULL. This function should be called for side effects, not return values.
Call this function to perform tests. If a tests fails, an informative error will be thrown. Otherwise silent.
A thin wrapper around check_tibble().
check_tidy_output(td, strict = TRUE)check_tidy_output(td, strict = TRUE)
td |
Output from a tidy method. |
strict |
Logical indicating whether the strict version of tests should be used. Defaults
to |
An invisible NULL. This function should be called for side effects, not return values.
Allowed column names in tidied tibbles
column_glossarycolumn_glossary
A tibble with 4 variables:
One of "glance", "augment" or "tidy".
Character name of allowed output column.
Character description of expected column contents.
column_glossarycolumn_glossary
Check whether or not a data-frame-like object has rownames
has_rownames(df)has_rownames(df)
df |
A data frame |
Logical indicating if df has rownames. If df is a tibble,
returns FALSE. If df is a data.frame, return FALSE if the rownames
are simply row numbers. If the rownames are anything other than the
return row numbers, returns TRUE.