Skip to content

Commit 5bc61d8

Browse files
authored
Merge pull request #151 from tidymodels/doc-consistency-changes
Doc consistency related to #143
2 parents 7e69c55 + 4f2e670 commit 5bc61d8

Some content is hidden

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

48 files changed

+216
-209
lines changed

DESCRIPTION

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Imports:
2929
tidyr,
3030
globals
3131
Roxygen: list(markdown = TRUE)
32-
RoxygenNote: 6.1.0.9000
32+
RoxygenNote: 6.1.1
3333
Suggests:
3434
testthat,
3535
knitr,
@@ -39,4 +39,3 @@ Suggests:
3939
xgboost,
4040
covr,
4141
sparklyr
42-

NEWS.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# parsnip 0.0.1.9000
22

3+
## New Features
4+
5+
* A "null model" is now available that fits a predictor-free model (using the mean of the outcome for regression or the mode for classification).
6+
37
## Other Changes
48

59
* `varying_args()` now has a `full` argument to control whether the full set
@@ -26,6 +30,8 @@ column names once (#107).
2630
* For multinomial regression using glmnet, `multi_predict()` now pulls the
2731
correct default penalty (#108).
2832

33+
34+
2935
# parsnip 0.0.1
3036

3137
First CRAN release

R/README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,27 +33,27 @@ list(
3333

3434
`func` describes the function call (instead of having it in open code). `protect` identifies the arguments that the user should _not_ be allowed to modify, and `defaults` is a list of values that should be set but the user _can_ override.
3535

36-
To create the model fit call, the `protect` arguments are populated with the appropriate objects (usually from the data set), and `rlang::call2` is used to create a call that can be executed. The `translate` function can be used to show the call prototype if there is need to see it (or debugging).
36+
To create the model fit call, the `protect` arguments are populated with the appropriate objects (usually from the data set), and `rlang::call2` is used to create a call that can be executed. The `translate()` function can be used to show the call prototype if there is need to see it (or debugging).
3737

3838
In the chunk above, the value of the `family` object is quoted (i.e., `expr(binomial)`). If this is not quotes, R will execute the value of the option when the package is compiled. In this case, the full function definition of the binomial family object will be embedded into the model call. Arguments are frequently quoted when making the call so that data objects or objects that don't exist when the package is compiled will not be embedded. (also see the enviromnets section below)
3939

4040
Additional notes:
4141

42-
* In cases where the model fit function is not a single function call, a wrapper function can be written to deal with this. See `parsnip::keras_mlp` and `parsnip::xgb_train`. this usually triggers package dependencies though.
43-
* The `defaults` argument is not the only place to set defaults. The `translate` method for an model specification gets the last word on arguments. It is also a good place to deal with common argument errors and to make defaults based on the _mode_ of the model (e.g. classification or regression).
42+
* In cases where the model fit function is not a single function call, a wrapper function can be written to deal with this. See `parsnip::keras_mlp()` and `parsnip::xgb_train()`. this usually triggers package dependencies though.
43+
* The `defaults` argument is not the only place to set defaults. The `translate()` method for an model specification gets the last word on arguments. It is also a good place to deal with common argument errors and to make defaults based on the _mode_ of the model (e.g. classification or regression).
4444
* Users can also pass in quoted arguments
4545

4646
## Environments
4747

48-
One of the first things that the `fit` function does is to make a new environment and store the data set and associated objects. For example:
48+
One of the first things that the `fit()` function does is to make a new environment and store the data set and associated objects. For example:
4949

5050
```r
5151
eval_env <- rlang::env()
5252
eval_env$data <- data
5353
eval_env$formula <- formula
5454
```
5555

56-
This is designed to avoid any issues when executing the call object on the data using `eval_tidy`.
56+
This is designed to avoid any issues when executing the call object on the data using `eval_tidy()`.
5757

5858
Any quoted arguments (such as the `family` example given above) are evaluated in this environment just before the model call is evaluated. For a user passes in an argument that is `floor(nrow(data)/3)`, this will be evaluated at this time in the captured environment.
5959

R/arguments.R

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,15 +67,15 @@ check_eng_args <- function(args, obj, core_args) {
6767

6868
#' Change elements of a model specification
6969
#'
70-
#' `set_args` can be used to modify the arguments of a model specification while
71-
#' `set_mode` is used to change the model's mode.
70+
#' `set_args()` can be used to modify the arguments of a model specification while
71+
#' `set_mode()` is used to change the model's mode.
7272
#'
7373
#' @param object A model specification.
7474
#' @param ... One or more named model arguments.
7575
#' @param mode A character string for the model type (e.g. "classification" or
7676
#' "regression")
7777
#' @return An updated model object.
78-
#' @details `set_args` will replace existing values of the arguments.
78+
#' @details `set_args()` will replace existing values of the arguments.
7979
#'
8080
#' @examples
8181
#' rand_forest()

R/boost_tree.R

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#' General Interface for Boosted Trees
44
#'
5-
#' `boost_tree` is a way to generate a _specification_ of a model
5+
#' `boost_tree()` is a way to generate a _specification_ of a model
66
#' before fitting and allows the model to be created using
77
#' different packages in R or via Spark. The main arguments for the
88
#' model are:
@@ -22,9 +22,9 @@
2222
#' }
2323
#' These arguments are converted to their specific names at the
2424
#' time that the model is fit. Other options and argument can be
25-
#' set using the `set_engine` function. If left to their defaults
25+
#' set using the `set_engine()` function. If left to their defaults
2626
#' here (`NULL`), the values are taken from the underlying model
27-
#' functions. If parameters need to be modified, `update` can be used
27+
#' functions. If parameters need to be modified, `update()` can be used
2828
#' in lieu of recreating the object from scratch.
2929
#'
3030
#' @param mode A single character string for the type of model.
@@ -48,7 +48,7 @@
4848
#' each iteration while `C5.0` samples once during traning.
4949
#' @details
5050
#' The data given to the function are not saved and are only used
51-
#' to determine the _mode_ of the model. For `boost_tree`, the
51+
#' to determine the _mode_ of the model. For `boost_tree()`, the
5252
#' possible modes are "regression" and "classification".
5353
#'
5454
#' The model can be created using the `fit()` function using the
@@ -87,13 +87,13 @@
8787
#'
8888
#' @note For models created using the spark engine, there are
8989
#' several differences to consider. First, only the formula
90-
#' interface to via `fit` is available; using `fit_xy` will
90+
#' interface to via `fit()` is available; using `fit_xy()` will
9191
#' generate an error. Second, the predictions will always be in a
9292
#' spark table format. The names will be the same as documented but
9393
#' without the dots. Third, there is no equivalent to factor
9494
#' columns in spark tables so class predictions are returned as
9595
#' character columns. Fourth, to retain the model object for a new
96-
#' R session (via `save`), the `model$fit` element of the `parsnip`
96+
#' R session (via `save()`), the `model$fit` element of the `parsnip`
9797
#' object should be serialized via `ml_save(object$fit)` and
9898
#' separately saved to disk. In a new session, the object can be
9999
#' reloaded and reattached to the `parsnip` object.
@@ -149,7 +149,7 @@ print.boost_tree <- function(x, ...) {
149149
#' @export
150150
#' @inheritParams boost_tree
151151
#' @param object A boosted tree model specification.
152-
#' @param ... Not used for `update`.
152+
#' @param ... Not used for `update()`.
153153
#' @param fresh A logical for whether the arguments should be
154154
#' modified in-place of or replaced wholesale.
155155
#' @return An updated model specification.

R/convert_data.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ convert_form_to_xy_fit <-function(
6464

6565
w <- as.vector(model.weights(mod_frame))
6666
if (!is.null(w) && !is.numeric(w))
67-
stop("'weights' must be a numeric vector", call. = FALSE)
67+
stop("`weights` must be a numeric vector", call. = FALSE)
6868

6969
offset <- as.vector(model.offset(mod_frame))
7070
if (!is.null(offset)) {
@@ -219,7 +219,7 @@ convert_xy_to_form_fit <- function(x, y, weights = NULL, y_name = "..y") {
219219

220220
if (!is.null(weights)) {
221221
if (!is.numeric(weights))
222-
stop("'weights' must be a numeric vector", call. = FALSE)
222+
stop("`weights` must be a numeric vector", call. = FALSE)
223223
if (length(weights) != nrow(x))
224224
stop("`weights` should have ", nrow(x), " elements", call. = FALSE)
225225
}

R/decision_tree.R

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#' General Interface for Decision Tree Models
44
#'
5-
#' `decision_tree` is a way to generate a _specification_ of a model
5+
#' `decision_tree()` is a way to generate a _specification_ of a model
66
#' before fitting and allows the model to be created using
77
#' different packages in R or via Spark. The main arguments for the
88
#' model are:
@@ -16,9 +16,9 @@
1616
#' }
1717
#' These arguments are converted to their specific names at the
1818
#' time that the model is fit. Other options and argument can be
19-
#' set using `set_engine`. If left to their defaults
19+
#' set using `set_engine()`. If left to their defaults
2020
#' here (`NULL`), the values are taken from the underlying model
21-
#' functions. If parameters need to be modified, `update` can be used
21+
#' functions. If parameters need to be modified, `update()` can be used
2222
#' in lieu of recreating the object from scratch.
2323
#'
2424
#' @inheritParams boost_tree
@@ -72,13 +72,13 @@
7272
#'
7373
#' @note For models created using the spark engine, there are
7474
#' several differences to consider. First, only the formula
75-
#' interface to via `fit` is available; using `fit_xy` will
75+
#' interface to via `fit()` is available; using `fit_xy()` will
7676
#' generate an error. Second, the predictions will always be in a
7777
#' spark table format. The names will be the same as documented but
7878
#' without the dots. Third, there is no equivalent to factor
7979
#' columns in spark tables so class predictions are returned as
8080
#' character columns. Fourth, to retain the model object for a new
81-
#' R session (via `save`), the `model$fit` element of the `parsnip`
81+
#' R session (via `save()`), the `model$fit` element of the `parsnip`
8282
#' object should be serialized via `ml_save(object$fit)` and
8383
#' separately saved to disk. In a new session, the object can be
8484
#' reloaded and reattached to the `parsnip` object.
@@ -112,7 +112,7 @@ decision_tree <-
112112

113113
#' @export
114114
print.decision_tree <- function(x, ...) {
115-
cat("Random Forest Model Specification (", x$mode, ")\n\n", sep = "")
115+
cat("Decision Tree Model Specification (", x$mode, ")\n\n", sep = "")
116116
model_printer(x, ...)
117117

118118
if(!is.null(x$method$fit$args)) {

R/engines.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ load_libs <- function(x, quiet, attach = FALSE) {
7777

7878
#' Declare a computational engine and specific arguments
7979
#'
80-
#' `set_engine` is used to specify which package or system will be used
80+
#' `set_engine()` is used to specify which package or system will be used
8181
#' to fit the model, along with any arguments specific to that software.
8282
#'
8383
#' @param object A model specification.

R/fit.R

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#' Fit a Model Specification to a Dataset
77
#'
8-
#' `fit` and `fit_xy` take a model specification, translate the required
8+
#' `fit()` and `fit_xy()` take a model specification, translate the required
99
#' code by substituting arguments, and execute the model fit
1010
#' routine.
1111
#'
@@ -22,25 +22,25 @@
2222
#' `catch`. See [fit_control()].
2323
#' @param ... Not currently used; values passed here will be
2424
#' ignored. Other options required to fit the model should be
25-
#' passed using `set_engine`.
26-
#' @details `fit` and `fit_xy` substitute the current arguments in the model
25+
#' passed using `set_engine()`.
26+
#' @details `fit()` and `fit_xy()` substitute the current arguments in the model
2727
#' specification into the computational engine's code, checks them
2828
#' for validity, then fits the model using the data and the
2929
#' engine-specific code. Different model functions have different
3030
#' interfaces (e.g. formula or `x`/`y`) and these functions translate
31-
#' between the interface used when `fit` or `fit_xy` were invoked and the one
31+
#' between the interface used when `fit()` or `fit_xy()` were invoked and the one
3232
#' required by the underlying model.
3333
#'
3434
#' When possible, these functions attempt to avoid making copies of the
3535
#' data. For example, if the underlying model uses a formula and
36-
#' `fit` is invoked, the original data are references
36+
#' `fit()` is invoked, the original data are references
3737
#' when the model is fit. However, if the underlying model uses
3838
#' something else, such as `x`/`y`, the formula is evaluated and
3939
#' the data are converted to the required format. In this case, any
4040
#' calls in the resulting model objects reference the temporary
4141
#' objects used to fit the model.
4242
#' @examples
43-
#' # Although `glm` only has a formula interface, different
43+
#' # Although `glm()` only has a formula interface, different
4444
#' # methods for specifying the model can be used
4545
#'
4646
#' library(dplyr)
@@ -94,10 +94,10 @@ fit.model_spec <-
9494
) {
9595
dots <- quos(...)
9696
if (any(names(dots) == "engine"))
97-
stop("Use `set_engine` to supply the engine.", call. = FALSE)
97+
stop("Use `set_engine()` to supply the engine.", call. = FALSE)
9898

9999
if (all(c("x", "y") %in% names(dots)))
100-
stop("`fit.model_spec` is for the formula methods. Use `fit_xy` instead.",
100+
stop("`fit.model_spec()` is for the formula methods. Use `fit_xy()` instead.",
101101
call. = FALSE)
102102
cl <- match.call(expand.dots = TRUE)
103103
# Create an environment with the evaluated argument objects. This will be
@@ -111,7 +111,7 @@ fit.model_spec <-
111111

112112
if (object$engine == "spark" && !inherits(eval_env$data, "tbl_spark"))
113113
stop(
114-
"spark objects can only be used with the formula interface to `fit` ",
114+
"spark objects can only be used with the formula interface to `fit()` ",
115115
"with a spark data object.", call. = FALSE
116116
)
117117

@@ -178,7 +178,7 @@ fit_xy.model_spec <-
178178
) {
179179
dots <- quos(...)
180180
if (any(names(dots) == "engine"))
181-
stop("Use `set_engine` to supply the engine.", call. = FALSE)
181+
stop("Use `set_engine()` to supply the engine.", call. = FALSE)
182182

183183
cl <- match.call(expand.dots = TRUE)
184184
eval_env <- rlang::env()
@@ -188,7 +188,7 @@ fit_xy.model_spec <-
188188

189189
if (object$engine == "spark")
190190
stop(
191-
"spark objects can only be used with the formula interface to `fit` ",
191+
"spark objects can only be used with the formula interface to `fit()` ",
192192
"with a spark data object.", call. = FALSE
193193
)
194194

@@ -305,7 +305,7 @@ check_interface <- function(formula, data, cl, model) {
305305
inher(formula, "formula", cl)
306306
inher(data, c("data.frame", "tbl_spark"), cl)
307307

308-
# Determine the `fit` interface
308+
# Determine the `fit()` interface
309309
form_interface <- !is.null(formula) & !is.null(data)
310310

311311
if (form_interface)
@@ -322,10 +322,10 @@ check_xy_interface <- function(x, y, cl, model) {
322322

323323
# rule out spark data sets that don't use the formula interface
324324
if (inherits(x, "tbl_spark") | inherits(y, "tbl_spark"))
325-
stop("spark objects can only be used with the formula interface via `fit` ",
325+
stop("spark objects can only be used with the formula interface via `fit()` ",
326326
"with a spark data object.", call. = FALSE)
327327

328-
# Determine the `fit` interface
328+
# Determine the `fit()` interface
329329
matrix_interface <- !is.null(x) & !is.null(y) && is.matrix(x)
330330
df_interface <- !is.null(x) & !is.null(y) && is.data.frame(x)
331331

R/fit_helpers.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# These functions are the go-betweens between parsnip::fit (or parsnip::fit_xy)
2-
# and the underlying model function (such as ranger::ranger). So if `fit_xy` is
2+
# and the underlying model function (such as ranger::ranger). So if `fit_xy()` is
33
# used to fit a ranger model, there needs to be a conversion from x/y format
44
# data to formula/data objects and so on.
55

@@ -66,7 +66,7 @@ form_form <-
6666
xy_xy <- function(object, env, control, target = "none", ...) {
6767

6868
if (inherits(env$x, "tbl_spark") | inherits(env$y, "tbl_spark"))
69-
stop("spark objects can only be used with the formula interface to `fit`",
69+
stop("spark objects can only be used with the formula interface to `fit()`",
7070
call. = FALSE)
7171

7272
object <- check_mode(object, levels(env$y))

0 commit comments

Comments
 (0)