Learn R Programming

⚠️There's a newer version (1.3.1) of this package.Take me there.

hardhat

Introduction

hardhat is a developer focused package designed to ease the creation of new modeling packages, while simultaneously promoting good R modeling package standards as laid out by the set of opinionated Conventions for R Modeling Packages.

hardhat has four main goals:

  • Easily, consistently, and robustly preprocess data at fit time and prediction time with mold() and forge().

  • Provide one source of truth for common input validation functions, such as checking if new data at prediction time contains the same required columns used at fit time.

  • Provide extra utility functions for additional common tasks, such as adding intercept columns, standardizing predict() output, and extracting valuable class and factor level information from the predictors.

  • Reimagine the base R preprocessing infrastructure of stats::model.matrix() and stats::model.frame() using the stricter approaches found in model_matrix() and model_frame().

The idea is to reduce the burden of creating a good modeling interface as much as possible, and instead let the package developer focus on writing the core implementation of their new model. This benefits not only the developer, but also the user of the modeling package, as the standardization allows users to build a set of “expectations” around what any modeling function should return, and how they should interact with it.

Installation

You can install the released version of hardhat from CRAN with:

install.packages("hardhat")

And the development version from GitHub with:

# install.packages("devtools")
devtools::install_github("tidymodels/hardhat")

Learning more

To learn about how to use hardhat, check out the vignettes:

  • vignette("mold", "hardhat"): Learn how to preprocess data at fit time with mold().

  • vignette("forge", "hardhat"): Learn how to preprocess new data at prediction time with forge().

  • vignette("package", "hardhat"): Learn how to use mold() and forge() to help in creating a new modeling package.

You can also watch Max Kuhn discuss how to use hardhat to build a new modeling package from scratch at the XI Jornadas de Usuarios de R conference here.

Contributing

This project is released with a Contributor Code of Conduct. By contributing to this project, you agree to abide by its terms.

Copy Link

Version

Install

install.packages('hardhat')

Monthly Downloads

157,568

Version

0.2.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Last Published

January 24th, 2022

Functions in hardhat (0.2.0)

extract_ptype

Extract a prototype
default_xy_blueprint

Default XY blueprint
delete_response

Delete the response from a terms object
mold

Mold data for modeling
model_frame

Construct a model frame
model_matrix

Construct a design matrix
new_default_formula_blueprint

Create a new default blueprint
forge

Forge prediction-ready data
scream

<U+0001F631> Scream.
shrink

Subset only required columns
new_formula_blueprint

Create a new preprocessing blueprint
new_model

Constructor for a base model
add_intercept_column

Add an intercept column to data
run_mold

Call mold$clean() and mold$process()
refresh_blueprint

Refresh a preprocessing blueprint
default_recipe_blueprint

Default recipe blueprint
default_formula_blueprint

Default formula blueprint
validate_column_names

Ensure that data contains required column names
validate_no_formula_duplication

Ensure no duplicate terms appear in formula
contr_one_hot

Contrast function for one-hot encodings
validate_outcomes_are_numeric

Ensure outcomes are all numeric
hardhat-package

hardhat: Construct Modeling Packages
validate_outcomes_are_univariate

Ensure that the outcome is univariate
modeling-package

Create a modeling package
model_offset

Extract a model offset
spruce

Spruce up predictions
is_blueprint

Is x a preprocessing blueprint?
update_blueprint

Update a preprocessing blueprint
validate_prediction_size

Ensure that predictions have the correct number of rows
tune

Mark arguments for tuning
validate_predictors_are_numeric

Ensure predictors are all numeric
standardize

Standardize the outcome
get_data_classes

Extract data classes from a data frame or matrix
get_levels

Extract factor levels from a data frame
hardhat-extract

Generics for object extraction
hardhat-example-data

Example data for hardhat
validate_outcomes_are_binary

Ensure that the outcome has binary factors
validate_outcomes_are_factors

Ensure that the outcome has only factor columns