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.

Copy Link

Version

Install

install.packages('hardhat')

Monthly Downloads

124,213

Version

0.1.1

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Davis Vaughan

Last Published

January 8th, 2020

Functions in hardhat (0.1.1)

extract_ptype

Extract a prototype
default_xy_blueprint

Default XY blueprint
is_blueprint

Is x a preprocessing blueprint?
add_intercept_column

Add an intercept column to data
default_formula_blueprint

Default formula blueprint
get_levels

Extract factor levels from a data frame
delete_response

Delete the response from a terms object
default_recipe_blueprint

Default recipe blueprint
forge

Forge prediction-ready data
get_data_classes

Extract data classes from a data frame or matrix
model_frame

Construct a model frame
new_model

Constructor for a base model
new_default_formula_blueprint

Create a new default blueprint
mold

Mold data for modeling
new_formula_blueprint

Create a new preprocessing blueprint
modeling-package

Create a modeling package
model_offset

Extract a model offset
model_matrix

Construct a design matrix
spruce

Spruce up predictions
standardize

Standardize the outcome
validate_column_names

Ensure that data contains required column names
update_blueprint

Update a preprocessing blueprint
shrink

Subset only required columns
run_mold

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

<U+0001F631> Scream.
refresh_blueprint

Refresh a preprocessing blueprint
validate_no_formula_duplication

Ensure no duplicate terms appear in formula
validate_predictors_are_numeric

Ensure predictors are all numeric
validate_outcomes_are_binary

Ensure that the outcome has binary factors
validate_outcomes_are_numeric

Ensure outcomes are all numeric
validate_outcomes_are_univariate

Ensure that the outcome is univariate
validate_outcomes_are_factors

Ensure that the outcome has only factor columns
validate_prediction_size

Ensure that predictions have the correct number of rows