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.
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.
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
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
259259get_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) {
363363is_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 ()
382382poke_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
415415descr_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