Skip to content

Commit a497d07

Browse files
authored
Merge pull request #95 from topepo/quosure-passthrough-tests
descriptor, documentation, and travis changes
2 parents 882c192 + 9b03513 commit a497d07

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

+4378
-2383
lines changed

.travis.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,16 @@ sudo: true
88
warnings_are_errors: false
99

1010
r:
11+
- 3.1
12+
- 3.2
13+
- oldrel
1114
- release
1215
- devel
1316

1417
env:
1518
- KERAS_BACKEND="tensorflow"
19+
global:
20+
- MAKEFLAGS="-j 2"
1621

1722
r_binary_packages:
1823
- rstan

DESCRIPTION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Package: parsnip
2-
Version: 0.0.0.9003
2+
Version: 0.0.0.9004
33
Title: A Common API to Modeling and analysis Functions
44
Description: A common interface is provided to allow users to specify a model without having to remember the different argument names across different functions or computational engines (e.g. R, spark, stan, etc).
55
Authors@R: c(

NAMESPACE

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ S3method(varying_args,model_spec)
5858
S3method(varying_args,recipe)
5959
S3method(varying_args,step)
6060
export("%>%")
61+
export(.cols)
6162
export(.dat)
62-
export(.n_cols)
63-
export(.n_facts)
64-
export(.n_levs)
65-
export(.n_obs)
66-
export(.n_preds)
63+
export(.facts)
64+
export(.lvls)
65+
export(.obs)
66+
export(.preds)
6767
export(.x)
6868
export(.y)
6969
export(C5.0_train)

NEWS.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
1+
# parsnip 0.0.0.9004
2+
3+
* Arguments to modeling functions are now captured as quosures.
4+
* `others` has been replaced by `...`
5+
* Data descriptor names have beemn changed and are now functions. The descriptor definitions for "cols" and "preds" have been switched.
6+
17
# parsnip 0.0.0.9003
28

39
* `regularization` was changed to `penalty` in a few models to be consistent with [this change](tidymodels/model-implementation-principles@08d3afd).
4-
* if a mode is not chosen in the model specification, it is assigned at the time of fit. [51](https://github.com/topepo/parsnip/issues/51)
10+
* If a mode is not chosen in the model specification, it is assigned at the time of fit. [51](https://github.com/topepo/parsnip/issues/51)
511
* The underlying modeling packages now are loaded by namespace. There will be some exceptions noted in the documentation for each model. For example, in some `predict` methods, the `earth` package will need to be attached to be fully operational.
612

713
# parsnip 0.0.0.9002

R/descriptors.R

Lines changed: 75 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
#' @name descriptors
2-
#' @aliases descriptors .n_obs .n_cols .n_preds .n_facts .n_levs .x .y .dat
2+
#' @aliases descriptors .obs .cols .preds .facts .lvls .x .y .dat
33
#' @title Data Set Characteristics Available when Fitting Models
44
#' @description When using the `fit()` functions there are some
55
#' variables that will be available for use in arguments. For
66
#' example, if the user would like to choose an argument value
7-
#' based on the current number of rows in a data set, the `.n_obs()`
7+
#' based on the current number of rows in a data set, the `.obs()`
88
#' function can be used. See Details below.
99
#' @details
1010
#' Existing functions:
1111
#' \itemize{
12-
#' \item `.n_obs()`: The current number of rows in the data set.
13-
#' \item `.n_cols()`: The number of columns in the data set that are
12+
#' \item `.obs()`: The current number of rows in the data set.
13+
#' \item `.preds()`: The number of columns in the data set that are
1414
#' associated with the predictors prior to dummy variable creation.
15-
#' \item `.n_preds()`: The number of predictors after dummy variables
16-
#' are created (if any).
17-
#' \item `.n_facts()`: The number of factor predictors in the dat set.
18-
#' \item `.n_levs()`: If the outcome is a factor, this is a table
15+
#' \item `.cols()`: The number of predictor columns availible after dummy
16+
#' variables are created (if any).
17+
#' \item `.facts()`: The number of factor predictors in the dat set.
18+
#' \item `.lvls()`: If the outcome is a factor, this is a table
1919
#' with the counts for each level (and `NA` otherwise).
2020
#' \item `.x()`: The predictors returned in the format given. Either a
2121
#' data frame or a matrix.
@@ -29,26 +29,26 @@
2929
#' For example, if you use the model formula `Sepal.Width ~ .` with the `iris`
3030
#' data, the values would be
3131
#' \preformatted{
32-
#' .n_cols() = 4 (the 4 columns in `iris`)
33-
#' .n_preds() = 5 (3 numeric columns + 2 from Species dummy variables)
34-
#' .n_obs() = 150
35-
#' .n_levs() = NA (no factor outcome)
36-
#' .n_facts() = 1 (the Species predictor)
37-
#' .y() = <vector> (Sepal.Width as a vector)
38-
#' .x() = <data.frame> (The other 4 columns as a data frame)
39-
#' .dat() = <data.frame> (The full data set)
32+
#' .preds() = 4 (the 4 columns in `iris`)
33+
#' .cols() = 5 (3 numeric columns + 2 from Species dummy variables)
34+
#' .obs() = 150
35+
#' .lvls() = NA (no factor outcome)
36+
#' .facts() = 1 (the Species predictor)
37+
#' .y() = <vector> (Sepal.Width as a vector)
38+
#' .x() = <data.frame> (The other 4 columns as a data frame)
39+
#' .dat() = <data.frame> (The full data set)
4040
#' }
4141
#'
4242
#' If the formula `Species ~ .` where used:
4343
#' \preformatted{
44-
#' .n_cols() = 4 (the 4 numeric columns in `iris`)
45-
#' .n_preds() = 4 (same)
46-
#' .n_obs() = 150
47-
#' .n_levs() = c(setosa = 50, versicolor = 50, virginica = 50)
48-
#' .n_facts() = 0
49-
#' .y() = <vector> (Species as a vector)
50-
#' .x() = <data.frame> (The other 4 columns as a data frame)
51-
#' .dat() = <data.frame> (The full data set)
44+
#' .preds() = 4 (the 4 numeric columns in `iris`)
45+
#' .cols() = 4 (same)
46+
#' .obs() = 150
47+
#' .lvls() = c(setosa = 50, versicolor = 50, virginica = 50)
48+
#' .facts() = 0
49+
#' .y() = <vector> (Species as a vector)
50+
#' .x() = <data.frame> (The other 4 columns as a data frame)
51+
#' .dat() = <data.frame> (The full data set)
5252
#' }
5353
#'
5454
#' To use these in a model fit, pass them to a model specification.
@@ -60,7 +60,7 @@
6060
#'
6161
#' data("lending_club")
6262
#'
63-
#' rand_forest(mode = "classification", mtry = .n_cols() - 2)
63+
#' rand_forest(mode = "classification", mtry = .cols() - 2)
6464
#' }
6565
#'
6666
#' When no descriptors are found, the computation of the descriptor values
@@ -70,23 +70,23 @@ NULL
7070

7171
#' @export
7272
#' @rdname descriptors
73-
.n_cols <- function() descr_env$.n_cols()
73+
.cols <- function() descr_env$.cols()
7474

7575
#' @export
7676
#' @rdname descriptors
77-
.n_preds <- function() descr_env$.n_preds()
77+
.preds <- function() descr_env$.preds()
7878

7979
#' @export
8080
#' @rdname descriptors
81-
.n_obs <- function() descr_env$.n_obs()
81+
.obs <- function() descr_env$.obs()
8282

8383
#' @export
8484
#' @rdname descriptors
85-
.n_levs <- function() descr_env$.n_levs()
85+
.lvls <- function() descr_env$.lvls()
8686

8787
#' @export
8888
#' @rdname descriptors
89-
.n_facts <- function() descr_env$.n_facts()
89+
.facts <- function() descr_env$.facts()
9090

9191
#' @export
9292
#' @rdname descriptors
@@ -116,24 +116,24 @@ get_descr_df <- function(formula, data) {
116116
tmp_dat <- convert_form_to_xy_fit(formula, data, indicators = FALSE)
117117

118118
if(is.factor(tmp_dat$y)) {
119-
.n_levs <- function() {
119+
.lvls <- function() {
120120
table(tmp_dat$y, dnn = NULL)
121121
}
122-
} else .n_levs <- function() { NA }
122+
} else .lvls <- function() { NA }
123123

124-
.n_cols <- function() {
124+
.preds <- function() {
125125
ncol(tmp_dat$x)
126126
}
127127

128-
.n_preds <- function() {
128+
.cols <- function() {
129129
ncol(convert_form_to_xy_fit(formula, data, indicators = TRUE)$x)
130130
}
131131

132-
.n_obs <- function() {
132+
.obs <- function() {
133133
nrow(data)
134134
}
135135

136-
.n_facts <- function() {
136+
.facts <- function() {
137137
sum(vapply(tmp_dat$x, is.factor, logical(1)))
138138
}
139139

@@ -150,11 +150,11 @@ get_descr_df <- function(formula, data) {
150150
}
151151

152152
list(
153-
.n_cols = .n_cols,
154-
.n_preds = .n_preds,
155-
.n_obs = .n_obs,
156-
.n_levs = .n_levs,
157-
.n_facts = .n_facts,
153+
.cols = .cols,
154+
.preds = .preds,
155+
.obs = .obs,
156+
.lvls = .lvls,
157+
.facts = .facts,
158158
.dat = .dat,
159159
.x = .x,
160160
.y = .y
@@ -233,23 +233,23 @@ get_descr_spark <- function(formula, data) {
233233

234234
obs <- dplyr::tally(data) %>% dplyr::pull()
235235

236-
.n_cols <- function() length(f_term_labels)
237-
.n_preds <- function() all_preds
238-
.n_obs <- function() obs
239-
.n_levs <- function() y_vals
240-
.n_facts <- function() factor_pred
236+
.cols <- function() all_preds
237+
.preds <- function() length(f_term_labels)
238+
.obs <- function() obs
239+
.lvls <- function() y_vals
240+
.facts <- function() factor_pred
241241
.x <- function() abort("Descriptor `.x()` not defined for Spark.")
242242
.y <- function() abort("Descriptor `.y()` not defined for Spark.")
243243
.dat <- function() abort("Descriptor `.dat()` not defined for Spark.")
244244

245245
# still need .x(), .y(), .dat() ?
246246

247247
list(
248-
.n_cols = .n_cols,
249-
.n_preds = .n_preds,
250-
.n_obs = .n_obs,
251-
.n_levs = .n_levs,
252-
.n_facts = .n_facts,
248+
.cols = .cols,
249+
.preds = .preds,
250+
.obs = .obs,
251+
.lvls = .lvls,
252+
.facts = .facts,
253253
.dat = .dat,
254254
.x = .x,
255255
.y = .y
@@ -258,25 +258,25 @@ get_descr_spark <- function(formula, data) {
258258

259259
get_descr_xy <- function(x, y) {
260260

261-
.n_levs <- if (is.factor(y)) {
261+
.lvls <- if (is.factor(y)) {
262262
function() table(y, dnn = NULL)
263263
} else {
264264
function() NA
265265
}
266266

267-
.n_cols <- function() {
267+
.cols <- function() {
268268
ncol(x)
269269
}
270270

271-
.n_preds <- function() {
271+
.preds <- function() {
272272
ncol(x)
273273
}
274274

275-
.n_obs <- function() {
275+
.obs <- function() {
276276
nrow(x)
277277
}
278278

279-
.n_facts <- function() {
279+
.facts <- function() {
280280
if(is.data.frame(x))
281281
sum(vapply(x, is.factor, logical(1)))
282282
else
@@ -296,11 +296,11 @@ get_descr_xy <- function(x, y) {
296296
}
297297

298298
list(
299-
.n_cols = .n_cols,
300-
.n_preds = .n_preds,
301-
.n_obs = .n_obs,
302-
.n_levs = .n_levs,
303-
.n_facts = .n_facts,
299+
.cols = .cols,
300+
.preds = .preds,
301+
.obs = .obs,
302+
.lvls = .lvls,
303+
.facts = .facts,
304304
.dat = .dat,
305305
.x = .x,
306306
.y = .y
@@ -363,11 +363,11 @@ has_any_descrs <- function(x) {
363363
is_descr <- function(x) {
364364

365365
descrs <- list(
366-
".n_cols",
367-
".n_preds",
368-
".n_obs",
369-
".n_levs",
370-
".n_facts",
366+
".cols",
367+
".preds",
368+
".obs",
369+
".lvls",
370+
".facts",
371371
".x",
372372
".y",
373373
".dat"
@@ -378,7 +378,7 @@ is_descr <- function(x) {
378378

379379
# Helpers for overwriting descriptors temporarily ------------------------------
380380

381-
# descrs = list of functions that actually eval to .n_cols()
381+
# descrs = list of functions that actually eval to .cols()
382382
poke_descrs <- function(descrs) {
383383

384384
descr_names <- names(descr_env)
@@ -414,13 +414,13 @@ scoped_descrs <- function(descrs, frame = caller_env()) {
414414
# with their actual implementations
415415
descr_env <- rlang::new_environment(
416416
data = list(
417-
.n_cols = function() abort("Descriptor context not set"),
418-
.n_preds = function() abort("Descriptor context not set"),
419-
.n_obs = function() abort("Descriptor context not set"),
420-
.n_levs = function() abort("Descriptor context not set"),
421-
.n_facts = function() abort("Descriptor context not set"),
422-
.x = function() abort("Descriptor context not set"),
423-
.y = function() abort("Descriptor context not set"),
424-
.dat = function() abort("Descriptor context not set")
417+
.cols = function() abort("Descriptor context not set"),
418+
.preds = function() abort("Descriptor context not set"),
419+
.obs = function() abort("Descriptor context not set"),
420+
.lvls = function() abort("Descriptor context not set"),
421+
.facts = function() abort("Descriptor context not set"),
422+
.x = function() abort("Descriptor context not set"),
423+
.y = function() abort("Descriptor context not set"),
424+
.dat = function() abort("Descriptor context not set")
425425
)
426426
)

0 commit comments

Comments
 (0)