Skip to content

Commit f49ff09

Browse files
committed
Move functions for finding args to /man/rmd, redocument
1 parent d7b371b commit f49ff09

17 files changed

+91
-82
lines changed

NAMESPACE

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,6 @@ export(boost_tree)
100100
export(check_empty_ellipse)
101101
export(check_final_param)
102102
export(control_parsnip)
103-
export(convert_args)
104103
export(convert_stan_interval)
105104
export(decision_tree)
106105
export(eval_args)

R/aaa.R

Lines changed: 0 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -30,56 +30,6 @@ convert_stan_interval <- function(x, level = 0.95, lower = TRUE) {
3030
res
3131
}
3232

33-
#' Find args for documentation
34-
#' @rdname convert_args
35-
#' @keywords internal
36-
#' @export
37-
convert_args <- function(model_name) {
38-
envir <- get_model_env()
39-
40-
args <-
41-
ls(envir) %>%
42-
tibble::tibble(name = .) %>%
43-
dplyr::filter(grepl("args", name)) %>%
44-
dplyr::mutate(model = sub("_args", "", name),
45-
args = purrr::map(name, ~envir[[.x]])) %>%
46-
dplyr::filter(grepl(model_name, model)) %>%
47-
tidyr::unnest(args) %>%
48-
dplyr::select(model:original) %>%
49-
full_join(get_arg_defaults(model_name),
50-
by = c("model", "engine", "parsnip", "original")) %>%
51-
mutate(original = dplyr::if_else(!is.na(default),
52-
paste0(original, " (", default, ")"),
53-
original)) %>%
54-
select(-default)
55-
56-
convert_df <- args %>%
57-
dplyr::select(-model) %>%
58-
tidyr::pivot_wider(names_from = engine, values_from = original)
59-
60-
convert_df %>%
61-
knitr::kable(col.names = paste0("**", colnames(convert_df), "**"))
62-
63-
}
64-
65-
#' @rdname convert_args
66-
#' @keywords internal
67-
#' @export
68-
get_arg_defaults <- function(model) {
69-
check_model_exists(model)
70-
gdf <- get(paste0("get_defaults_", model))
71-
gdf()
72-
}
73-
74-
#' @rdname convert_args
75-
#' @keywords internal
76-
#' @export
77-
get_arg <- function(ns, f, arg) {
78-
args <- formals(getFromNamespace(f, ns))
79-
args <- as.list(args)
80-
as.character(args[[arg]])
81-
}
82-
8333
# ------------------------------------------------------------------------------
8434
# nocov
8535

man/boost_tree.Rd

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

man/convert_args.Rd

Lines changed: 0 additions & 18 deletions
This file was deleted.

man/rmd/boost-tree.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are below:
47

58
## xgboost
@@ -76,7 +79,7 @@ get_defaults_boost_tree <- function() {
7679
7780
)
7881
}
79-
parsnip::convert_args("boost_tree")
82+
convert_args("boost_tree")
8083
```
8184

8285
For spark, the default `mtry` is the square root of the number of predictors for classification, and one-third of the predictors for regression.

man/rmd/decision-tree.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are below:
47

58
## rpart
@@ -66,6 +69,6 @@ get_defaults_decision_tree <- function() {
6669
"decision_tree", "spark", "min_n", "min_instances_per_node", get_arg("sparklyr", "ml_decision_tree", "min_instances_per_node"),
6770
)
6871
}
69-
parsnip::convert_args("decision_tree")
72+
convert_args("decision_tree")
7073
```
7174

man/rmd/linear-reg.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are below.
47

58
## lm
@@ -82,6 +85,6 @@ get_defaults_linear_reg <- function() {
8285
"linear_reg", "keras", "penalty", "penalty", get_arg("parsnip", "keras_mlp", "penalty"),
8386
)
8487
}
85-
parsnip::convert_args("linear_reg")
88+
convert_args("linear_reg")
8689
```
8790

man/rmd/logistic-reg.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call.
47
For this type of model, the template of the fit calls are below.
58

@@ -83,6 +86,6 @@ get_defaults_logistic_reg <- function() {
8386
"logistic_reg", "keras", "penalty", "penalty", get_arg("parsnip", "keras_mlp", "penalty"),
8487
)
8588
}
86-
parsnip::convert_args("logistic_reg")
89+
convert_args("logistic_reg")
8790
```
8891

man/rmd/mars.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call.
47
For this type of model, the template of the fit calls are below.
58

@@ -37,6 +40,6 @@ get_defaults_mars <- function() {
3740
"mars", "earth", "prune_method", "pmethod", get_arg("earth", "earth.fit", "pmethod")[2]
3841
)
3942
}
40-
parsnip::convert_args("mars")
43+
convert_args("mars")
4144
```
4245

man/rmd/mlp.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call.
47
For this type of model, the template of the fit calls are below:
58

@@ -57,6 +60,6 @@ get_defaults_mlp <- function() {
5760
"mlp", "nnet", "epochs", "maxit", get_arg("nnet", "nnet.default", "maxit"),
5861
)
5962
}
60-
parsnip::convert_args("mlp")
63+
convert_args("mlp")
6164
```
6265

man/rmd/multinom-reg.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call.
47
For this type of model, the template of the fit calls are below.
58

@@ -66,6 +69,6 @@ get_defaults_multinom_reg <- function() {
6669
"multinom_reg", "nnet", "penalty", "decay", get_arg("nnet", "nnet.default", "decay"),
6770
)
6871
}
69-
parsnip::convert_args("multinom_reg")
72+
convert_args("multinom_reg")
7073
```
7174

man/rmd/nearest-neighbor.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are below:
47

58
## kknn
@@ -38,6 +41,6 @@ get_defaults_nearest_neighbor <- function() {
3841
"nearest_neighbor", "kknn", "dist_power", "distance", get_arg("kknn", "train.kknn", "distance"),
3942
)
4043
}
41-
parsnip::convert_args("nearest_neighbor")
44+
convert_args("nearest_neighbor")
4245
```
4346

man/rmd/rand-forest.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call.
47
For this type of model, the template of the fit calls are below:
58

@@ -83,7 +86,7 @@ get_defaults_rand_forest <- function() {
8386
"rand_forest", "spark", "min_n", "min_instances_per_node", get_arg("sparklyr", "ml_random_forest", "min_instances_per_node"),
8487
)
8588
}
86-
parsnip::convert_args("rand_forest")
89+
convert_args("rand_forest")
8790
```
8891

8992
- For randomForest and spark, the default `mtry` is the square root of the number of predictors for classification, and one-third of the predictors for regression.

man/rmd/setup.Rmd

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
```{r, include = FALSE}
2+
convert_args <- function(model_name) {
3+
envir <- get_model_env()
4+
5+
args <-
6+
ls(envir) %>%
7+
tibble::tibble(name = .) %>%
8+
dplyr::filter(grepl("args", name)) %>%
9+
dplyr::mutate(model = sub("_args", "", name),
10+
args = purrr::map(name, ~envir[[.x]])) %>%
11+
dplyr::filter(grepl(model_name, model)) %>%
12+
tidyr::unnest(args) %>%
13+
dplyr::select(model:original) %>%
14+
full_join(get_arg_defaults(model_name),
15+
by = c("model", "engine", "parsnip", "original")) %>%
16+
mutate(original = dplyr::if_else(!is.na(default),
17+
paste0(original, " (", default, ")"),
18+
original)) %>%
19+
select(-default)
20+
21+
convert_df <- args %>%
22+
dplyr::select(-model) %>%
23+
tidyr::pivot_wider(names_from = engine, values_from = original)
24+
25+
convert_df %>%
26+
knitr::kable(col.names = paste0("**", colnames(convert_df), "**"))
27+
28+
}
29+
30+
get_arg_defaults <- function(model) {
31+
check_model_exists(model)
32+
gdf <- get(paste0("get_defaults_", model))
33+
gdf()
34+
}
35+
36+
get_arg <- function(ns, f, arg) {
37+
args <- formals(getFromNamespace(f, ns))
38+
args <- as.list(args)
39+
as.character(args[[arg]])
40+
}
41+
42+
```

man/rmd/surv-reg.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call. For this type of model, the template of the fit calls are below.
47

58
## flexsurv
@@ -37,6 +40,6 @@ get_defaults_surv_reg <- function() {
3740
"surv_reg", "survival", "dist", "dist", NA,
3841
)
3942
}
40-
parsnip::convert_args("surv_reg")
43+
convert_args("surv_reg")
4144
```
4245

man/rmd/svm-poly.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call.
47
For this type of model, the template of the fit calls are below:
58

@@ -36,6 +39,6 @@ get_defaults_svm_poly <- function() {
3639
"svm_poly", "kernlab", "margin", "epsilon", "0.1",
3740
)
3841
}
39-
parsnip::convert_args("svm_poly")
42+
convert_args("svm_poly")
4043
```
4144

man/rmd/svm-rbf.Rmd

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# Engine Details
22

3+
```{r, child = "setup.Rmd", include = FALSE}
4+
```
5+
36
Engines may have pre-set default arguments when executing the model fit call.
47
For this type of model, the template of the fit calls are below:
58

@@ -63,6 +66,6 @@ get_defaults_svm_rbf <- function() {
6366
"svm_rbf", "liquidSVM", "rbf_sigma", "gammas", "varies",
6467
)
6568
}
66-
parsnip::convert_args("svm_rbf")
69+
convert_args("svm_rbf")
6770
```
6871

0 commit comments

Comments
 (0)