You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: inst/README-DOCS.md
+61-7Lines changed: 61 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,7 @@
1
1
# About the parsnip documentation system
2
2
3
+
## Background
4
+
3
5
parsnip uses three concepts to describe models:
4
6
5
7
- The _model type_ specifies its mathematical structure.
@@ -21,9 +23,23 @@ Each modeling function defined in parsnip has a documentation file (with extensi
21
23
22
24
Also, each combination of engine and model type has a corresponding `.Rd` file (a.k.a the "engine-specific" documentation files). The list of known engines is also shown in the `.Rd` file for the main function.
23
25
26
+
If you are creating a new engine documentation file, the steps are:
27
+
28
+
1. Use roxygen comments to generate the main `.Rd` file that R's help system uses.
29
+
2. Create an `.Rmd` file that has the details of the engine.
30
+
3. Knit the `.Rmd` file to `.md` so the `.Rd` file from step 1 can link it.
31
+
4. Once you are done, run `devtools::document()` (or use the RStudio IDE) to build the help files.
32
+
33
+
**Before you read the rest**, you probably don't have to generate the help files in this way yourself:
34
+
35
+
* This process only applies for engines whose model function is in parsnip. If your R package defines a new model, then you don't have to do all of this (unless you want to).
36
+
37
+
* If you make a PR with a new engine, you can work on the `.Rmd` file and the tidymodels folks can go through the process of merging it in (but let us know if you want us to do that in the PR).
24
38
25
39
## Creating the engine-specific `.Rd` files
26
40
41
+
Once create by `document()`, the `.Rd` files live in the `man` directory. They are not handwritten but are automatically generated from `.R` files in the `R` directory.
42
+
27
43
How do we generate these `.Rd` files? We'll use an example with `poisson_reg()` and the `"zeroinfl"` engine.
28
44
29
45
Each model/engine combination has its own `.R` file with a naming convention reflecting the contents (`poisson_reg_zeroinfl.R`). This file has a description of the type of model and the underlying function that is used for that engine:
@@ -40,15 +56,46 @@ as well as a directive for the `.Rd` file name to be created:
40
56
41
57
The engine markdown file (`poisson_reg_zeroinfl.md`) is made by the developer offline.
42
58
43
-
## Creating the engine-specific `.md` files
59
+
Take a look at the [actual file](https://github.com/tidymodels/parsnip/blob/main/R/poisson_reg_zeroinfl.R) if you want to see it all.
60
+
61
+
To summarize: the relationship between these `.R` files and the `.md` files that they include is:
62
+
63
+
```
64
+
:
65
+
├── R
66
+
│ ├── :
67
+
│ ├── :
68
+
│ ├── bag_tree.R. <- model definition code that has the Sexprs
69
+
│ ├── bag_tree_C5.0.R <- wrapper around bag_tree_C5.0.md (below)
70
+
│ ├── bag_tree_rpart.R <- wrapper around bag_tree_rpart.md (below)
71
+
: :
72
+
: :
73
+
├── man
74
+
│ ├── rmd
75
+
│ │ ├──:
76
+
│ │ ├── :
77
+
│ │ ├── aaa.Rmd <- sourced by all other Rmd files
78
+
│ │ ├── :
79
+
│ │ ├── :
80
+
│ │ ├── bag_tree_C5.0.Rmd <- engine details for the C5.0 engine only
81
+
│ │ ├── bag_tree_C5.0.md
82
+
│ │ ├── bag_tree_rpart.Rmd
83
+
│ │ ├── bag_tree_rpart.md
84
+
: : :
85
+
```
86
+
87
+
88
+
## Creating the engine-specific `.md` files for `.Rmd` files
44
89
45
90
How do we make these markdown files? These are created by corresponding `.Rmd` files contained in `parsnip/man/rmd/`. There are `.Rmd` files for the engines defined in parsnip as well as the extension packages listed by `parsnip:::extensions()`.
46
91
47
92
Each `.Rmd` file uses `parsnip/man/rmd/aaa.Rmd` as a child document. This file defines helper functions for the engine-specific documentation and loads some specific packages.
48
93
49
94
The `.Rmd` files use packages that are not formally parsnip dependencies (these are listed in `aaa.Rmd`). It also requires the parsnip extension packages defined in `parsnip:::extensions()`.
50
95
51
-
The `.Rmd` files have a consistent structure and there are numerous examples of these files in the package. The main sections are:
96
+
There is an internal helper function (`parsnip:::install_engine_packages()`) that will install the extension packages as well as a few others that are required to build all of the documentation files.
97
+
98
+
The `.Rmd` files have a consistent structure and there are [numerous examples](https://github.com/tidymodels/parsnip/tree/main/man/rmd) of these files in the package. The main sections are:
52
99
53
100
- The list of possible engines.
54
101
- The list of tuning parameters, if any, and other arguments of interest.
@@ -57,11 +104,15 @@ The `.Rmd` files have a consistent structure and there are numerous examples of
57
104
58
105
To convert the `.Rmd` files to `.md`, use the function `knit_engine_docs()`. After this, use `devtools::document()` to create the engine specific `.Rd` files.
59
106
107
+
**Please** look at the output of the knitting; if there are errors, they will show up there.
108
+
60
109
To test the results, do a hard restart of the R session (i.e., do not use `load_all()`).
61
110
62
111
## The main function `.Rd` files
63
112
64
-
This type of file determines the engine-specific `.Rd` files for the model function and enumerates their values in a bulleted list. For example, `poisson_reg.R` has the line:
113
+
_This section has information that is probably only needed by the core developers._
114
+
115
+
Recall that the `.Rd` files are created from the `.R` files. There are some fancy things that we do in the `.R` files to list the engines. For example, `poisson_reg.R` has the line:
0 commit comments