NOTE: This vignette describes how extend the broom generics in an external package. To use the broom generics in an external you can
Import broom as you would normally.
This guide describes how to extend the
augment() generics. broom recently started re-exporting these generics from the
modelgenerics is not yet on CRAN, nor is the version of broom that uses
modelgenerics. You’ll need to wait for these CRAN releases (timeline TBD at the moment) before release your package to CRAN if you extend broom in the manner described here.
augment()generics from the
You can re-export generics from broom itself, but
modelgenerics is a much lighter dependency.
The dustpan package demonstrates use of
modeltests, and you may find it helpful to browse.
Next you’ll need to re-export the appropriate tidying methods. If you plan to implement a
glance() method, for example, you can re-export the glance generic by adding the following somewhere in your package
#' @importFrom modelgenerics glance #' @export modelgenerics::glance
devtools::document() for these changes to take effect.
Note: please do not define
augment() generics in your package. This will result in namespace conflicts whenever your package is used along other packages that also export tidying methods.
This part is mostly up to you, although there’s lots of advice in
Now that you have a tidying method, you’ll want to test it. In addition to testing the specific functionality of your tidying methods, you should also pass the standardized tests exported from modeltests.
To import these tests you’ll need to add
Suggests, which you can accomplish with:
# once modeltests makes its way onto CRAN: # usethis::use_package("modeltests", "Suggests") # until then: remotes::install_github("alexpghayes/modeltests") usethis::use_dev_package("modeltests")
You can then write tests for your tidiers following the advice in
If you are using tidiers from broom, such as
tidy.lm(), then you will need to depend on
broom, probably via
Similarly, if you are using tidiers from
broom.mixed, you’ll need to
You can import
broom.mixed separately from
broom, or you can mix and match them however you want.
I think so, although I haven’t tested this yet. This is on the TODO list at the moment.
If you are introducing new arguments or column names in output, you’ll need to make a pull request to
modeltests to add the new argument/column names to the glossary of allowed names.
If you’d like to change the test specifications, or if you find a bug in the tests, open an issue in
As a last resort, you can set
strict = FALSE to run only a bare minimum of tests. This is not recommended.