Skip to content

Commit 812e40e

Browse files
authored
Merge pull request #113 from tidymodels/rc-0.1.0
Rc 0.1.0
2 parents 5c78533 + bcc1ea1 commit 812e40e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

64 files changed

+772
-401
lines changed

.Rbuildignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,9 @@
88
^\.Rproj\.user$
99
^man-roxygen$
1010
^graphics$
11+
^\.github$
1112
^\.github/workflows/R-CMD-check\.yaml$
1213
^\.github/workflows/pr-commands\.yaml$
14+
^LICENSE\.md$
15+
^cran-comments\.md$
16+
^CRAN-RELEASE$

CRAN-RELEASE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This package was submitted to CRAN on 2019-12-06.
2+
Once it is accepted, delete this file and tag the release (commit 34ea0a04ea).

DESCRIPTION

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
Package: hardhat
2-
Title: A Toolkit for the Construction of Modeling Packages
3-
Version: 0.0.0.9001
2+
Title: Construct Modeling Packages
3+
Version: 0.1.0
44
Authors@R: c(
55
person("Davis", "Vaughan", , "[email protected]", c("aut", "cre")),
66
person("Max", "Kuhn", , "[email protected]", c("aut")),
77
person("RStudio", role = "cph"))
88
Maintainer: Davis Vaughan <[email protected]>
9-
Description: Provides infrastructure for building new modeling packages,
10-
including functionality around preprocessing, predicting, and validating
11-
input.
12-
License: GPL-2
9+
Description: Building modeling packages is hard. A large amount of effort
10+
generally goes into providing an implementation for a new method that is
11+
efficient, fast, and correct, but often less emphasis is put on the user
12+
interface. A good interface requires specialized knowledge about S3 methods
13+
and formulas, which the average package developer might not have.
14+
The goal of 'hardhat' is to reduce the burden around building new modeling
15+
packages by providing functionality for preprocessing, predicting, and
16+
validating input.
17+
License: MIT + file LICENSE
1318
Encoding: UTF-8
1419
LazyData: true
15-
RoxygenNote: 6.1.1
20+
RoxygenNote: 7.0.1
1621
Roxygen: list(markdown = TRUE)
1722
Suggests:
1823
recipes,
@@ -25,9 +30,8 @@ Suggests:
2530
devtools
2631
Imports:
2732
glue,
28-
rlang (>= 0.4.0),
33+
rlang (>= 0.4.1),
2934
tibble,
30-
zeallot,
3135
vctrs (>= 0.2.0)
3236
URL: https://github.com/tidymodels/hardhat
3337
BugReports: https://github.com/tidymodels/hardhat/issues

LICENSE

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YEAR: 2019
2+
COPYRIGHT HOLDER: Davis Vaughan

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# MIT License
2+
3+
Copyright (c) 2019 Davis Vaughan
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,4 +106,3 @@ importFrom(vctrs,vec_cast.integer)
106106
importFrom(vctrs,vec_cast.list)
107107
importFrom(vctrs,vec_cast.logical)
108108
importFrom(vctrs,vec_cast.vctrs_list_of)
109-
importFrom(zeallot,"%<-%")

R/aaa.R

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#' @importFrom rlang abort is_missing arg_match := %||%
22
#' @importFrom glue glue
33
#' @importFrom tibble tibble
4-
#' @importFrom zeallot %<-%
54
NULL
65

76
# stats related imports
@@ -28,18 +27,3 @@ NULL
2827
#' @importFrom vctrs vec_cast.POSIXlt
2928
#' @importFrom vctrs vec_cast.vctrs_list_of
3029
NULL
31-
32-
# for zeallot
33-
utils::globalVariables(
34-
c(
35-
".predictors",
36-
".outcomes",
37-
"predictors",
38-
"outcomes",
39-
"ptypes",
40-
"ptype",
41-
"extras",
42-
"predictors_lst",
43-
"outcomes_lst"
44-
)
45-
)

R/blueprint-formula-default.R

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#'
1515
#' @param ... Not used.
1616
#'
17+
#' @return
18+
#'
19+
#' For `default_formula_blueprint()`, a formula blueprint.
20+
#'
1721
#' @details
1822
#'
1923
#' While not different from base R, the behavior of expanding factors into
@@ -89,7 +93,7 @@
8993
#' to [mold()], then they are extracted with [model_offset()].
9094
#'
9195
#' - If `intercept = TRUE` in the original call to [mold()], then an
92-
#' intecept column is added.
96+
#' intercept column is added.
9397
#'
9498
#' - It coerces the result of the above steps to a tibble.
9599
#'
@@ -198,10 +202,8 @@
198202
#'
199203
#' # An informative error is thrown when `indicators = FALSE` and
200204
#' # factors are present in interaction terms or in inline functions
201-
#' \dontrun{
202-
#' mold(Sepal.Width ~ Sepal.Length:Species, train, blueprint = blueprint_no_indicators)
203-
#' mold(Sepal.Width ~ paste0(Species), train, blueprint = blueprint_no_indicators)
204-
#' }
205+
#' try(mold(Sepal.Width ~ Sepal.Length:Species, train, blueprint = blueprint_no_indicators))
206+
#' try(mold(Sepal.Width ~ paste0(Species), train, blueprint = blueprint_no_indicators))
205207
#'
206208
#' # ---------------------------------------------------------------------------
207209
#' # Multivariate outcomes
@@ -343,17 +345,22 @@ mold_formula_default_clean <- function(blueprint, data) {
343345

344346
# mold - formula - process
345347
mold_formula_default_process <- function(blueprint, data) {
346-
347-
c(blueprint, predictors_lst) %<-% mold_formula_default_process_predictors(
348+
processed <- mold_formula_default_process_predictors(
348349
blueprint = blueprint,
349350
data = data
350351
)
351352

352-
c(blueprint, outcomes_lst) %<-% mold_formula_default_process_outcomes(
353+
blueprint <- processed$blueprint
354+
predictors_lst <- processed$terms_lst
355+
356+
processed <- mold_formula_default_process_outcomes(
353357
blueprint = blueprint,
354358
data = data
355359
)
356360

361+
blueprint <- processed$blueprint
362+
outcomes_lst <- processed$terms_lst
363+
357364
# nuke formula environment before returning
358365
formula_empty_env <- nuke_formula_environment(blueprint$formula)
359366
blueprint <- update_blueprint(blueprint, formula = formula_empty_env)
@@ -470,17 +477,22 @@ forge_formula_default_clean <- function(blueprint, new_data, outcomes) {
470477
}
471478

472479
forge_formula_default_process <- function(blueprint, predictors, outcomes, extras) {
473-
474-
c(blueprint, predictors_lst) %<-% forge_formula_default_process_predictors(
480+
processed <- forge_formula_default_process_predictors(
475481
blueprint = blueprint,
476482
predictors = predictors
477483
)
478484

479-
c(blueprint, outcomes_lst) %<-% forge_formula_default_process_outcomes(
485+
blueprint <- processed$blueprint
486+
predictors_lst <- processed$terms_lst
487+
488+
processed <- forge_formula_default_process_outcomes(
480489
blueprint = blueprint,
481490
outcomes = outcomes
482491
)
483492

493+
blueprint <- processed$blueprint
494+
outcomes_lst <- processed$terms_lst
495+
484496
extras <- c(
485497
extras,
486498
out$extras$final(predictors_lst$extras, outcomes_lst$extras)

R/blueprint-recipe-default.R

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@
1414
#'
1515
#' @param ... Not used.
1616
#'
17+
#' @return
18+
#'
19+
#' For `default_recipe_blueprint()`, a recipe blueprint.
20+
#'
1721
#' @section Mold:
1822
#'
1923
#' When `mold()` is used with the default recipe blueprint:
@@ -182,17 +186,20 @@ mold_recipe_default_process <- function(blueprint, data) {
182186
recipe <- recipes::prep(blueprint$recipe, training = data, fresh = blueprint$fresh)
183187
blueprint <- update_blueprint(blueprint, recipe = recipe)
184188

185-
c(blueprint, predictors_lst) %<-% mold_recipe_default_process_predictors(
186-
blueprint = blueprint,
187-
data = data
188-
)
189+
processed <- mold_recipe_default_process_predictors(blueprint = blueprint, data = data)
189190

190-
c(blueprint, outcomes_lst) %<-% mold_recipe_default_process_outcomes(
191-
blueprint = blueprint,
192-
data = data
193-
)
191+
blueprint <- processed$blueprint
192+
predictors_lst <- processed$terms_lst
194193

195-
c(blueprint, extras) %<-% mold_recipe_default_process_extras(blueprint, data)
194+
processed <- mold_recipe_default_process_outcomes(blueprint = blueprint, data = data)
195+
196+
blueprint <- processed$blueprint
197+
outcomes_lst <- processed$terms_lst
198+
199+
processed <- mold_recipe_default_process_extras(blueprint, data)
200+
201+
blueprint <- processed$blueprint
202+
extras <- processed$extras
196203

197204
extras <- c(
198205
extras,
@@ -344,16 +351,22 @@ forge_recipe_default_process <- function(blueprint, predictors, outcomes, extras
344351
outcomes <- baked_data[, processed_outcome_names, drop = FALSE]
345352
}
346353

347-
c(blueprint, predictors_lst) %<-% forge_recipe_default_process_predictors(
354+
processed <- forge_recipe_default_process_predictors(
348355
blueprint = blueprint,
349356
predictors = predictors
350357
)
351358

352-
c(blueprint, outcomes_lst) %<-% forge_recipe_default_process_outcomes(
359+
blueprint <- processed$blueprint
360+
predictors_lst <- processed$terms_lst
361+
362+
processed <- forge_recipe_default_process_outcomes(
353363
blueprint = blueprint,
354364
outcomes = outcomes
355365
)
356366

367+
blueprint <- processed$blueprint
368+
outcomes_lst <- processed$terms_lst
369+
357370
extras <- forge_recipe_default_process_extras(
358371
extras,
359372
rec,

R/blueprint-xy-default.R

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@
1515
#'
1616
#' @param ... Not used.
1717
#'
18+
#' @return
19+
#'
20+
#' For `default_xy_blueprint()`, an XY blueprint.
21+
#'
1822
#' @details
1923
#'
2024
#' As documented in [standardize()], if `y` is a _vector_, then the returned
@@ -88,9 +92,7 @@
8892
#' processed <- mold(train_x, train_y)
8993
#'
9094
#' # Can't do this!
91-
#' \dontrun{
92-
#' forge(test_x, processed$blueprint, outcomes = TRUE)
93-
#' }
95+
#' try(forge(test_x, processed$blueprint, outcomes = TRUE))
9496
#'
9597
#' # Need to use the full test set, including `y`
9698
#' forge(test, processed$blueprint, outcomes = TRUE)
@@ -106,9 +108,7 @@
106108
#'
107109
#' # This throws an informative error that tell you
108110
#' # to include an `".outcome"` column in `new_data`.
109-
#' \dontrun{
110-
#' forge(iris, processed_vec$blueprint, outcomes = TRUE)
111-
#' }
111+
#' try(forge(iris, processed_vec$blueprint, outcomes = TRUE))
112112
#'
113113
#' test2 <- test
114114
#' test2$.outcome <- test2$Species
@@ -178,14 +178,20 @@ get_mold_xy_default_function_set <- function() {
178178

179179
# mold - xy - clean
180180
mold_xy_default_clean <- function(blueprint, x, y) {
181-
c(blueprint, x) %<-% mold_xy_default_clean_predictors(blueprint, x)
181+
cleaned <- mold_xy_default_clean_predictors(blueprint, x)
182+
183+
blueprint <- cleaned$blueprint
184+
x <- cleaned$x
182185

183186
# Special case `y = NULL` as a 0 column variation on `x`
184187
if (is.null(y)) {
185188
y <- x[, 0L, drop = FALSE]
186189
}
187190

188-
c(blueprint, y) %<-% mold_xy_default_clean_outcomes(blueprint, y)
191+
cleaned <- mold_xy_default_clean_outcomes(blueprint, y)
192+
193+
blueprint <- cleaned$blueprint
194+
y <- cleaned$y
189195

190196
out$mold$clean_xy(blueprint, x, y)
191197
}
@@ -202,9 +208,15 @@ mold_xy_default_clean_outcomes <- function(blueprint, y) {
202208

203209
# mold - xy - process
204210
mold_xy_default_process <- function(blueprint, x, y) {
211+
processed <- mold_xy_default_process_predictors(blueprint, x)
205212

206-
c(blueprint, predictors_lst) %<-% mold_xy_default_process_predictors(blueprint, x)
207-
c(blueprint, outcomes_lst) %<-% mold_xy_default_process_outcomes(blueprint, y)
213+
blueprint <- processed$blueprint
214+
predictors_lst <- processed$terms_lst
215+
216+
processed <- mold_xy_default_process_outcomes(blueprint, y)
217+
218+
blueprint <- processed$blueprint
219+
outcomes_lst <- processed$terms_lst
208220

209221
ptypes <- out$ptypes$final(predictors_lst$ptype, outcomes_lst$ptype)
210222
extras <- out$extras$final(predictors_lst$extras, outcomes_lst$extras)
@@ -266,9 +278,15 @@ forge_xy_default_clean <- function(blueprint, new_data, outcomes) {
266278
}
267279

268280
forge_xy_default_process <- function(blueprint, predictors, outcomes, extras) {
281+
processed <- forge_xy_default_process_predictors(blueprint, predictors)
282+
283+
blueprint <- processed$blueprint
284+
predictors_lst <- processed$terms_lst
285+
286+
processed <- forge_xy_default_process_outcomes(blueprint, outcomes)
269287

270-
c(blueprint, predictors_lst) %<-% forge_xy_default_process_predictors(blueprint, predictors)
271-
c(blueprint, outcomes_lst) %<-% forge_xy_default_process_outcomes(blueprint, outcomes)
288+
blueprint <- processed$blueprint
289+
outcomes_lst <- processed$terms_lst
272290

273291
extras <- c(
274292
extras,

0 commit comments

Comments
 (0)