Skip to content

Commit 4c31cf6

Browse files
authored
Merge pull request #295 from tidymodels/s3-reg-again
S3 registration fixes, round 2
2 parents 36497e6 + 65344e9 commit 4c31cf6

File tree

117 files changed

+4984
-4408
lines changed

Some content is hidden

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

117 files changed

+4984
-4408
lines changed

.Rbuildignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ derby.log
1616
^README\.Rmd$
1717
^\.github$
1818
^CODE_OF_CONDUCT\.md$
19+
^README\.html$

NAMESPACE

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@ S3method(print,rand_forest)
5353
S3method(print,surv_reg)
5454
S3method(print,svm_poly)
5555
S3method(print,svm_rbf)
56+
S3method(tidy,model_fit)
57+
S3method(tidy,nullmodel)
5658
S3method(translate,boost_tree)
5759
S3method(translate,decision_tree)
5860
S3method(translate,default)
@@ -159,7 +161,7 @@ export(show_model_info)
159161
export(surv_reg)
160162
export(svm_poly)
161163
export(svm_rbf)
162-
export(tidy.model_fit)
164+
export(tidy)
163165
export(translate)
164166
export(translate.default)
165167
export(update_dot_check)
@@ -186,6 +188,7 @@ importFrom(dplyr,tally)
186188
importFrom(dplyr,vars)
187189
importFrom(generics,fit)
188190
importFrom(generics,fit_xy)
191+
importFrom(generics,tidy)
189192
importFrom(generics,varying_args)
190193
importFrom(glue,glue_collapse)
191194
importFrom(magrittr,"%>%")

R/nullmodel.R

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,3 +170,23 @@ null_model <-
170170
class(out) <- make_classes("null_model")
171171
out
172172
}
173+
174+
175+
176+
#' Tidy method for null models
177+
#'
178+
#' Return the results of `nullmodel` as a tibble
179+
#'
180+
#' @param x A `nullmodel` object.
181+
#' @param ... Not used.
182+
#' @return A tibble with column `value`.
183+
#' @export
184+
#' @examples
185+
#' nullmodel(iris[,-5], iris$Species) %>% tidy()
186+
#'
187+
#' nullmodel(mtcars[,-1], mtcars$mpg) %>% tidy()
188+
189+
tidy.nullmodel <- function(x, ...) {
190+
tibble::tibble(value = x$value)
191+
}
192+

R/reexports.R

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ generics::fit
1010
#' @importFrom generics fit_xy
1111
#' @export
1212
generics::fit_xy
13+
14+
#' @importFrom generics tidy
15+
#' @export
16+
generics::tidy

R/zzz.R

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

33
.onLoad <- function(libname, pkgname) {
44
s3_register("broom::tidy", "model_fit")
5+
s3_register("broom::tidy", "nullmodel")
56
}
67

78

README.Rmd

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
---
2+
output: github_document
3+
---
14

25
<!-- README.md is generated from README.Rmd. Please edit that file -->
36

@@ -10,15 +13,15 @@ knitr::opts_chunk$set(
1013
)
1114
```
1215

13-
# parsnip <a href='https://tidymodels.github.io/parsnip/'><img src='man/figures/logo.png' align="right" height="139" /></a>
16+
# parsnip
1417

1518
<!-- badges: start -->
16-
[![Build Status](https://travis-ci.org/tidymodels/parsnip.svg?branch=master)](https://travis-ci.org/tidymodels/parsnip)
1719
[![R build status](https://github.com/tidymodels/parsnip/workflows/R-CMD-check/badge.svg)](https://github.com/tidymodels/parsnip)
1820
[![Coverage status](https://codecov.io/gh/tidymodels/parsnip/branch/master/graph/badge.svg)](https://codecov.io/github/tidymodels/parsnip?branch=master)
19-
[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/parsnip)](https://cran.rstudio.com/package=parsnip)
21+
[![CRAN status](https://www.r-pkg.org/badges/version/parsnip)](https://CRAN.R-project.org/package=parsnip)
2022
[![Downloads](http://cranlogs.r-pkg.org/badges/parsnip)](https://cran.rstudio.com/package=parsnip)
2123
[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
24+
2225
<!-- badges: end -->
2326

2427
## Introduction
@@ -116,6 +119,10 @@ rand_forest(mtry = 10, trees = 2000) %>%
116119
fit(mpg ~ ., data = mtcars)
117120
```
118121

122+
A list of all `parsnip` models across different CRAN packages can be found at
123+
[`tidymodels.org`](https://www.tidymodels.org/find/).
124+
125+
Data sets previously found in `parsnip` are now find in the `modeldata` package.
119126

120127

121128
## Contributing

README.html

Lines changed: 538 additions & 0 deletions
Large diffs are not rendered by default.

README.md

Lines changed: 55 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,30 @@
11

22
<!-- README.md is generated from README.Rmd. Please edit that file -->
33

4-
5-
6-
# parsnip <a href='https://tidymodels.github.io/parsnip/'><img src='man/figures/logo.png' align="right" height="139" /></a>
4+
# parsnip
75

86
<!-- badges: start -->
9-
[![Build Status](https://travis-ci.org/tidymodels/parsnip.svg?branch=master)](https://travis-ci.org/tidymodels/parsnip)
10-
[![R build status](https://github.com/tidymodels/parsnip/workflows/R-CMD-check/badge.svg)](https://github.com/tidymodels/parsnip)
11-
[![Coverage status](https://codecov.io/gh/tidymodels/parsnip/branch/master/graph/badge.svg)](https://codecov.io/github/tidymodels/parsnip?branch=master)
12-
[![CRAN\_Status\_Badge](http://www.r-pkg.org/badges/version/parsnip)](https://cran.rstudio.com/package=parsnip)
7+
8+
[![R build
9+
status](https://github.com/tidymodels/parsnip/workflows/R-CMD-check/badge.svg)](https://github.com/tidymodels/parsnip)
10+
[![Coverage
11+
status](https://codecov.io/gh/tidymodels/parsnip/branch/master/graph/badge.svg)](https://codecov.io/github/tidymodels/parsnip?branch=master)
12+
[![CRAN
13+
status](https://www.r-pkg.org/badges/version/parsnip)](https://CRAN.R-project.org/package=parsnip)
1314
[![Downloads](http://cranlogs.r-pkg.org/badges/parsnip)](https://cran.rstudio.com/package=parsnip)
1415
[![lifecycle](https://img.shields.io/badge/lifecycle-maturing-blue.svg)](https://www.tidyverse.org/lifecycle/#maturing)
16+
1517
<!-- badges: end -->
1618

1719
## Introduction
1820

19-
The goal of parsnip is to provide a tidy, unified interface to models that can be used to try a range of models without getting bogged down in the syntactical minutiae of the underlying packages.
21+
The goal of parsnip is to provide a tidy, unified interface to models
22+
that can be used to try a range of models without getting bogged down in
23+
the syntactical minutiae of the underlying packages.
2024

2125
## Installation
2226

23-
24-
```r
27+
``` r
2528
# The easiest way to get parsnip is to install all of tidymodels:
2629
install.packages("tidymodels")
2730

@@ -33,13 +36,14 @@ install.packages("parsnip")
3336
devtools::install_github("tidymodels/parsnip")
3437
```
3538

36-
3739
## Getting started
3840

39-
One challenge with different modeling functions available in R _that do the same thing_ is that they can have different interfaces and arguments. For example, to fit a random forest _regression_ model, we might have:
41+
One challenge with different modeling functions available in R *that do
42+
the same thing* is that they can have different interfaces and
43+
arguments. For example, to fit a random forest *regression* model, we
44+
might have:
4045

41-
42-
```r
46+
``` r
4347
# From randomForest
4448
rf_1 <- randomForest(
4549
y ~ .,
@@ -69,25 +73,32 @@ rf_3 <- ml_random_forest(
6973
)
7074
```
7175

72-
Note that the model syntax can be very different and that the argument names (and formats) are also different. This is a pain if you switch between implementations.
73-
74-
In this example:
76+
Note that the model syntax can be very different and that the argument
77+
names (and formats) are also different. This is a pain if you switch
78+
between implementations.
7579

76-
* the **type** of model is "random forest",
77-
* the **mode** of the model is "regression" (as opposed to classification, etc), and
78-
* the computational **engine** is the name of the R package.
80+
In this example:
7981

82+
- the **type** of model is “random forest”,
83+
- the **mode** of the model is “regression” (as opposed to
84+
classification, etc), and
85+
- the computational **engine** is the name of the R package.
8086

8187
The goals of parsnip are to:
8288

83-
* Separate the definition of a model from its evaluation.
84-
* Decouple the model specification from the implementation (whether the implementation is in R, spark, or something else). For example, the user would call `rand_forest` instead of `ranger::ranger` or other specific packages.
85-
* Harmonize argument names (e.g. `n.trees`, `ntrees`, `trees`) so that users only need to remember a single name. This will help _across_ model types too so that `trees` will be the same argument across random forest as well as boosting or bagging.
89+
- Separate the definition of a model from its evaluation.
90+
- Decouple the model specification from the implementation (whether
91+
the implementation is in R, spark, or something else). For example,
92+
the user would call `rand_forest` instead of `ranger::ranger` or
93+
other specific packages.
94+
- Harmonize argument names (e.g. `n.trees`, `ntrees`, `trees`) so that
95+
users only need to remember a single name. This will help *across*
96+
model types too so that `trees` will be the same argument across
97+
random forest as well as boosting or bagging.
8698

8799
Using the example above, the `parsnip` approach would be:
88100

89-
90-
```r
101+
``` r
91102
library(parsnip)
92103

93104
rand_forest(mtry = 10, trees = 2000) %>%
@@ -105,10 +116,10 @@ rand_forest(mtry = 10, trees = 2000) %>%
105116
#> Computational engine: ranger
106117
```
107118

108-
The engine can be easily changed. To use Spark, the change is straightforward:
119+
The engine can be easily changed. To use Spark, the change is
120+
straightforward:
109121

110-
111-
```r
122+
``` r
112123
rand_forest(mtry = 10, trees = 2000) %>%
113124
set_engine("spark") %>%
114125
set_mode("regression")
@@ -123,15 +134,14 @@ rand_forest(mtry = 10, trees = 2000) %>%
123134

124135
Either one of these model specifications can be fit in the same way:
125136

126-
127-
```r
137+
``` r
128138
rand_forest(mtry = 10, trees = 2000) %>%
129139
set_engine("ranger", importance = "impurity") %>%
130140
set_mode("regression") %>%
131141
fit(mpg ~ ., data = mtcars)
132142
#> parsnip model object
133143
#>
134-
#> Fit time: 69ms
144+
#> Fit time: 81ms
135145
#> Ranger result
136146
#>
137147
#> Call:
@@ -145,14 +155,24 @@ rand_forest(mtry = 10, trees = 2000) %>%
145155
#> Target node size: 5
146156
#> Variable importance mode: impurity
147157
#> Splitrule: variance
148-
#> OOB prediction error (MSE): 5.859577
149-
#> R squared (OOB): 0.8386862
158+
#> OOB prediction error (MSE): 5.947154
159+
#> R squared (OOB): 0.8362753
150160
```
151161

162+
A list of all `parsnip` models across different CRAN packages can be
163+
found at [`tidymodels.org`](https://www.tidymodels.org/find/).
152164

165+
Data sets previously found in `parsnip` are now find in the `modeldata`
166+
package.
153167

154168
## Contributing
155169

156-
If you encounter a bug, please file a minimal reproducible example on [GitHub](https://github.com/tidymodels/parsnip/issues). For questions and other discussion, please use [community.rstudio.com](https://community.rstudio.com/).
170+
If you encounter a bug, please file a minimal reproducible example on
171+
[GitHub](https://github.com/tidymodels/parsnip/issues). For questions
172+
and other discussion, please use
173+
[community.rstudio.com](https://community.rstudio.com/).
157174

158-
Please note that the parsnip project is released with a [Contributor Code of Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html). By contributing to this project, you agree to abide by its terms.
175+
Please note that the parsnip project is released with a [Contributor
176+
Code of
177+
Conduct](https://contributor-covenant.org/version/2/0/CODE_OF_CONDUCT.html).
178+
By contributing to this project, you agree to abide by its terms.

_pkgdown.yml

Lines changed: 13 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ reference:
2222
- linear_reg
2323
- logistic_reg
2424
- mars
25-
- mlp
26-
- multinom_reg
25+
- mlp
26+
- multinom_reg
2727
- nearest_neighbor
2828
- null_model
2929
- rand_forest
30-
- surv_reg
30+
- surv_reg
3131
- svm_poly
3232
- svm_rbf
3333
- title: Infrastructure
@@ -37,7 +37,7 @@ reference:
3737
- fit.model_spec
3838
- fit_xy
3939
- fit_control
40-
- model_fit
40+
- model_fit
4141
- model_spec
4242
- predict.model_fit
4343
- multi_predict
@@ -49,14 +49,8 @@ reference:
4949
- varying
5050
- varying_args
5151

52-
- title: Data
53-
contents:
54-
- lending_club
55-
- wa_churn
56-
- check_times
57-
5852
- title: Developer Tools
59-
contents:
53+
contents:
6054
- set_new_model
6155
- starts_with("set_model_")
6256
- set_dependency
@@ -69,22 +63,20 @@ reference:
6963

7064
navbar:
7165
left:
72-
- text: Basic Usage
73-
href: articles/parsnip_Intro.html
74-
- text: Model List
75-
href: articles/articles/Models.html
66+
- text: Basic Usage
67+
href: articles/parsnip_Intro.html
7668
- text: "Articles"
7769
menu:
7870
- text: Regression modeling
79-
href: articles/articles/Regression.html
71+
href: articles/articles/Regression.html
8072
- text: Classification modeling
81-
href: articles/articles/Classification.html
73+
href: articles/articles/Classification.html
8274
- text: Making a parsnip model from scratch
83-
href: articles/articles/Scratch.html
84-
- text: Evaluating submodels with the same model object
85-
href: articles/articles/Submodels.html
75+
href: articles/articles/Scratch.html
76+
- text: Evaluating submodels with the same model object
77+
href: articles/articles/Submodels.html
8678
- text: News
87-
href: news/index.html
79+
href: news/index.html
8880
- text: Reference
8981
href: reference/index.html
9082

0 commit comments

Comments
 (0)