Skip to content

Commit 45f804e

Browse files
topepojuliasilgehfrickEmilHvitfeldt
authored
Revised documentation system (#631)
* include md instead of Rmd * don't commit engine md files * remove extra files * additional templates * move some argument code to a function * move legacy code to generate engine doc lists and seealso * rename file * refactor code since all files reside within parsnip * better printing of the engine list * fix bug in param object call * avoid deprecation warning * added missing mode * add files for SDA model * new multilevelmod engine docs * prototypes for engine extension package notes * some brulee files * add a file with engine/model information * keep extension package name * use superscripted numbers for default engine and extensions * Refactor the engine and mode information in the model files * remove files no longer used * temp remove check for extenstion pkgs * move setup.Rmd to aaa.Rmd * remove unused engine doc functions * added a note with PR number * more info on models with extension packages * add a link to the "find" page for models * updated model database * fix bug related to engine names with underscores * brulee engine files * combined replicate files * Wrote a readme document and added notes about it in engine files * more code cleanup * fix some extension package doc issues * add a readme for the documentation system * change path to readme doc * add two functions back * also merge model info by mode. * mode-specific dependencies for rpart * avoid failing for "Packages unavailable to check Rd xrefs" * Edits to README-DOCS, mainly so I think I will be able to come back to this and understand it * Apply suggestions from code review Co-authored-by: Julia Silge <julia.silge@gmail.com> Co-authored-by: Hannah Frick <hfrick@users.noreply.github.com> * add install_engine_packages * add list_md_problems() to find errors and warnings in engine specific docs * document list_md_problems() * add a few more packages * add issue summary post-knit * doc update * update model about model = TRUE for survival * list to table * notes about mode * remove "dynamically" * more error trapping during knit * changes for new brulee version * Rework explanation of what is/isn't in our tab-delimited file * Update R/rand_forest.R * Update R/rule_fit.R * Update R/svm_linear.R * Update R/survival_reg.R * Remove details on glmnet not using the formula interface * Redocument * doc update * retain md files * rm randomForest. See tidymodels/extratests/41 * temporarily disable windows testing (tensorflow install) Co-authored-by: Julia Silge <julia.silge@gmail.com> Co-authored-by: Hannah Frick <hfrick@users.noreply.github.com> Co-authored-by: Emil Hvitfeldt <emilhhvitfeldt@gmail.com>
1 parent 0c7f440 commit 45f804e

File tree

412 files changed

+16013
-1399
lines changed

Some content is hidden

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

412 files changed

+16013
-1399
lines changed

.github/workflows/R-CMD-check.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ jobs:
2323
matrix:
2424
config:
2525
- {os: macOS-latest, r: 'release'}
26-
- {os: windows-latest, r: 'release'}
26+
# disable until tensorflow install is worked out
27+
# - {os: windows-latest, r: 'release'}
2728
# Use older ubuntu to maximise backward compatibility
2829
- {os: ubuntu-18.04, r: 'devel', http-user-agent: 'release'}
2930
- {os: ubuntu-18.04, r: 'release'}

DESCRIPTION

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ BugReports: https://github.com/tidymodels/parsnip/issues
1818
Depends:
1919
R (>= 2.10)
2020
Imports:
21+
cli,
2122
dplyr (>= 0.8.0.1),
2223
generics (>= 0.1.0.9000),
2324
globals,
@@ -50,8 +51,8 @@ Suggests:
5051
mgcv,
5152
modeldata,
5253
nlme,
53-
randomForest,
5454
ranger (>= 0.12.0),
55+
remotes,
5556
rmarkdown,
5657
rpart,
5758
sparklyr (>= 1.0.0),
@@ -80,6 +81,7 @@ Config/Needs/website:
8081
tidymodels/tidymodels,
8182
tidyverse/tidytemplate,
8283
xgboost
84+
Config/rcmdcheck/ignore-inconsequential-notes: true
8385
Encoding: UTF-8
8486
LazyData: true
8587
Roxygen: list(markdown = TRUE)

NAMESPACE

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,9 @@ export(glance)
206206
export(has_multi_predict)
207207
export(is_varying)
208208
export(keras_mlp)
209+
export(knit_engine_docs)
209210
export(linear_reg)
211+
export(list_md_problems)
210212
export(logistic_reg)
211213
export(make_call)
212214
export(make_classes)
@@ -286,6 +288,7 @@ export(tune)
286288
export(update_dot_check)
287289
export(update_engine_parameters)
288290
export(update_main_parameters)
291+
export(update_model_info_file)
289292
export(varying)
290293
export(varying_args)
291294
export(xgb_train)

R/C5_rules_C5.0.R

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#' C5.0 rule-based classification models
2+
#'
3+
#' [C50::C5.0()] fits a model that derives feature rules from a tree for
4+
#' prediction. A single tree or boosted ensemble can be used. [rules::c5_fit()]
5+
#' is a wrapper around this function.
6+
#'
7+
#' @includeRmd man/rmd/C5_rules_C5.0.md details
8+
#'
9+
#' @name details_C5_rules_C5.0
10+
#' @keywords internal
11+
NULL
12+
13+
# See inst/README-DOCS.md for a description of how these files are processed

R/aaa.R

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ utils::globalVariables(
9191
"max_terms", "max_tree", "model", "name", "num_terms", "penalty", "trees",
9292
"sub_neighbors", ".pred_class", "x", "y", "predictor_indicators",
9393
"compute_intercept", "remove_intercept", "estimate", "term",
94-
"call_info", "component", "component_id", "func", "tunable")
94+
"call_info", "component", "component_id", "func", "pkg", ".order", "item", "tunable")
9595
)
9696

9797
# nocov end

R/aaa_models.R

Lines changed: 0 additions & 215 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,218 +1081,3 @@ get_encoding <- function(model) {
10811081
}
10821082
res
10831083
}
1084-
1085-
#' Tools for dynamically documenting packages
1086-
#'
1087-
#' @description
1088-
#' These are functions used to create dynamic documentation in Rd files
1089-
#' based on which parsnip-related packages are loaded by the user.
1090-
#'
1091-
#' These functions can be used to make dynamic lists of documentation help
1092-
#' files. \pkg{parsnip} uses these along with files in `man/rmd` which
1093-
#' contain expanded documentation for specific model/engine combinations.
1094-
#' [find_engine_files()] looks for files that have the pattern
1095-
#' `details_{model}_{engine}.Rd` to link to. These files are generated by files
1096-
#' named `man/rmd/{model}_{engine}.Rmd`. `make_engine_list()` creates a
1097-
#' list seen at the top of the model Rd files while `make_seealso_list()`
1098-
#' populates the list seen in "See Also" below. See the details section.
1099-
#'
1100-
#' @param mod A character string for the model file (e.g. "linear_reg")
1101-
#' @param pkg A character string for the package where the function is invoked.
1102-
#' @return
1103-
#' `make_engine_list()` returns a character string that creates a
1104-
#' bulleted list of links to more specific help files.
1105-
#'
1106-
#' `make_seealso_list()` returns a formatted character string of links.
1107-
#'
1108-
#' `find_engine_files()` returns a tibble.
1109-
#' @details
1110-
#' The \pkg{parsnip} documentation is generated _dynamically_. Part of the Rd
1111-
#' file populates a list of engines that depends on what packages are loaded
1112-
#' *at the time that the man file is loaded*. For example, if
1113-
#' another package has a new engine for `linear_reg()`, the
1114-
#' `parsnip::linear_reg()` help can show a link to a detailed help page in the
1115-
#' other package.
1116-
#'
1117-
#' To enable this, the process for a package developer is to:
1118-
#'
1119-
#' 1. Create an engine-specific R file in the `R` directory with the name
1120-
#' `{model}_{engine}.R` (e.g. `boost_tree_C5.0.R`). This has a small amount of
1121-
#' documentation, as well as the directives "`@name details_{model}_{engine}`"
1122-
#' and "`@includeRmd man/rmd/{model}_{engine}.Rmd details`".
1123-
#'
1124-
#' 2. Copy the file in \pkg{parsnip} that is in `man/rmd/setup.Rmd` and put
1125-
#' it in the same place in your package.
1126-
#'
1127-
#' 3. Write your own `man/rmd/{model}_{engine}.Rmd` file. This can include
1128-
#' packages that are not listed in the DESCRIPTION file. Those are only
1129-
#' required when the documentation file is created locally (probably using
1130-
#' [devtools::document()]).
1131-
#'
1132-
#' 4. Run [devtools::document()] so that the Rmd content is included in the
1133-
#' Rd file.
1134-
#'
1135-
#' The examples in \pkg{parsnip} can provide guidance for how to organize
1136-
#' technical information about the models.
1137-
#' @name doc-tools
1138-
#' @keywords internal
1139-
#' @export
1140-
#' @examples
1141-
#' find_engine_files("linear_reg")
1142-
#' cat(make_engine_list("linear_reg"))
1143-
find_engine_files <- function(mod, pkg = "parsnip") {
1144-
1145-
requireNamespace(pkg, quietly = TRUE)
1146-
# Get available topics
1147-
topic_names <- search_for_engine_docs(mod)
1148-
if (length(topic_names) == 0) {
1149-
return(character(0))
1150-
}
1151-
1152-
# Subset for our model function
1153-
eng <- strsplit(topic_names, "_")
1154-
eng <- purrr::map_chr(eng, ~ .x[length(.x)])
1155-
eng <- tibble::tibble(engine = eng, topic = topic_names)
1156-
1157-
# Combine them to keep the order in which they were registered
1158-
all_eng <- get_from_env(mod) %>% dplyr::distinct(engine)
1159-
all_eng$.order <- 1:nrow(all_eng)
1160-
eng <- dplyr::left_join(eng, all_eng, by = "engine")
1161-
eng <- eng[order(eng$.order),]
1162-
1163-
# Determine and label default engine
1164-
default <- get_default_engine(mod, pkg)
1165-
eng$default <- ifelse(eng$engine == default, " (default)", "")
1166-
1167-
eng
1168-
}
1169-
1170-
#' @export
1171-
#' @rdname doc-tools
1172-
make_engine_list <- function(mod, pkg = "parsnip") {
1173-
eng <- find_engine_files(mod, pkg)
1174-
1175-
if (length(eng) == 0) {
1176-
return("No engines were found within the currently loaded packages.\n\n")
1177-
} else {
1178-
main <- paste("The engine-specific pages for this model are listed ",
1179-
"below and contain the details:\n\n")
1180-
}
1181-
1182-
res <-
1183-
glue::glue(" \\item \\code{\\link[|eng$topic|]{|eng$engine|} |eng$default| }",
1184-
.open = "|", .close = "|")
1185-
1186-
res <- paste0(main, "\\itemize{\n", paste0(res, collapse = "\n"), "\n}")
1187-
res
1188-
}
1189-
1190-
get_default_engine <- function(mod, pkg= "parsnip") {
1191-
cl <- rlang::call2(mod, .ns = pkg)
1192-
rlang::eval_tidy(cl)$engine
1193-
}
1194-
1195-
#' @export
1196-
#' @rdname doc-tools
1197-
make_seealso_list <- function(mod, pkg= "parsnip") {
1198-
requireNamespace(pkg, quietly = TRUE)
1199-
eng <- find_engine_files(mod, pkg)
1200-
1201-
main <- c("\\code{\\link[=fit.model_spec]{fit()}}",
1202-
"\\code{\\link[=set_engine]{set_engine()}}",
1203-
"\\code{\\link[=update]{update()}}")
1204-
1205-
if (length(eng) == 0) {
1206-
return(paste0(main, collapse = ", "))
1207-
}
1208-
1209-
res <-
1210-
glue::glue("\\code{\\link[|eng$topic|]{|eng$engine| engine details}}",
1211-
.open = "|", .close = "|")
1212-
1213-
if (pkg != "parsnip") {
1214-
main <- NULL
1215-
}
1216-
paste0(c(main, res), collapse = ", ")
1217-
}
1218-
1219-
# These will never have documentation and we can avoid searching them.
1220-
excl_pkgs <-
1221-
c("C50", "Cubist", "earth", "flexsurv", "forecast", "glmnet",
1222-
"keras", "kernlab", "kknn", "klaR", "LiblineaR", "liquidSVM",
1223-
"magrittr", "MASS", "mda", "mixOmics", "naivebayes", "nnet",
1224-
"prophet", "pscl", "randomForest", "ranger", "rpart", "rstanarm",
1225-
"sparklyr", "stats", "survival", "xgboost", "xrf")
1226-
1227-
search_for_engine_docs <- function(mod) {
1228-
all_deps <- get_from_env(paste0(mod, "_pkgs"))
1229-
all_deps <- unlist(all_deps$pkg)
1230-
all_deps <- unique(c("parsnip", all_deps))
1231-
1232-
all_deps <- all_deps[!(all_deps %in% excl_pkgs)]
1233-
res <- purrr::map(all_deps, find_details_topics, mod = mod)
1234-
res <- unique(unlist(res))
1235-
res
1236-
}
1237-
1238-
find_details_topics <- function(pkg, mod) {
1239-
meta_loc <- system.file("Meta/Rd.rds", package = pkg)
1240-
meta_loc <- meta_loc[meta_loc != ""]
1241-
if (length(meta_loc) > 0) {
1242-
topic_names <- readRDS(meta_loc)$Name
1243-
res <- grep(paste0("details_", mod), topic_names, value = TRUE)
1244-
if (length(res) > 0) {
1245-
res <- paste0(pkg, ":", res)
1246-
}
1247-
} else {
1248-
res <- character(0)
1249-
}
1250-
res
1251-
}
1252-
1253-
1254-
# For use in `set_engine()` docs
1255-
generate_set_engine_bullets <- function() {
1256-
env <- get_model_env()
1257-
models <- env$models
1258-
info <- rlang::env_get_list(env, models)
1259-
1260-
model_engines <- purrr::map(info, get_sorted_unique_engines)
1261-
1262-
model_prefixes <- glue::glue(
1263-
"\\code{\\link[=.{models}.]{.{models}.()}}:",
1264-
.open = ".{",
1265-
.close = "}."
1266-
)
1267-
1268-
bullets <- purrr::map2(
1269-
.x = model_prefixes,
1270-
.y = model_engines,
1271-
.f = combine_prefix_with_engines
1272-
)
1273-
1274-
bullets <- glue::glue("\\item {bullets}")
1275-
bullets <- glue::glue_collapse(bullets, sep = "\n")
1276-
bullets <- paste("\\itemize{", bullets, "}", sep = "\n")
1277-
1278-
bullets
1279-
}
1280-
1281-
sort_c <- function(x) {
1282-
withr::with_collate("C", sort(x))
1283-
}
1284-
get_sorted_unique_engines <- function(x) {
1285-
engines <- x$engine
1286-
engines <- unique(engines)
1287-
engines <- sort_c(engines)
1288-
engines
1289-
}
1290-
combine_prefix_with_engines <- function(prefix, engines) {
1291-
if (length(engines) == 0L) {
1292-
engines <- "No engines currently available"
1293-
} else {
1294-
engines <- glue::glue_collapse(engines, sep = ", ")
1295-
}
1296-
1297-
glue::glue("{prefix} {engines}")
1298-
}

R/bag_mars.R

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,7 @@
55
#' `bag_mars()` defines an ensemble of generalized linear models that use
66
#' artificial features for some predictors. These features resemble hinge
77
#' functions and the result is a model that is a segmented regression in small
8-
#' dimensions.
9-
#'
10-
#' There are different ways to fit this model. The method of estimation is
11-
#' chosen by setting the model _engine_.
8+
#' dimensions. This function can fit classification and regression models.
129
#'
1310
#' \Sexpr[stage=render,results=rd]{parsnip:::make_engine_list("bag_mars")}
1411
#'

R/bag_mars_earth.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#' Bagged MARS via earth
2+
#'
3+
#' [baguette::bagger()] creates an collection of MARS models forming an
4+
#' ensemble. All models in the ensemble are combined to produce a final prediction.
5+
#'
6+
#' @includeRmd man/rmd/bag_mars_earth.md details
7+
#'
8+
#' @name details_bag_mars_earth
9+
#' @keywords internal
10+
NULL
11+
12+
# See inst/README-DOCS.md for a description of how these files are processed

R/bag_tree.R

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
#'
33
#' @description
44
#'
5-
#' `bag_tree()` defines an ensemble of decision trees.
6-
#'
7-
#' There are different ways to fit this model. The method of estimation is
8-
#' chosen by setting the model _engine_.
5+
#' `bag_tree()` defines an ensemble of decision trees. This function can fit
6+
#' classification, regression, and censored regression models.
97
#'
108
#' \Sexpr[stage=render,results=rd]{parsnip:::make_engine_list("bag_tree")}
119
#'

R/bag_tree_C5.0.R

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#' Bagged trees via C5.0
2+
#'
3+
#' [baguette::bagger()] creates an collection of decision trees forming an
4+
#' ensemble. All trees in the ensemble are combined to produce a final prediction.
5+
#'
6+
#' @includeRmd man/rmd/bag_tree_C5.0.md details
7+
#'
8+
#' @name details_bag_tree_C5.0
9+
#' @keywords internal
10+
NULL
11+
12+
# See inst/README-DOCS.md for a description of how these files are processed

0 commit comments

Comments
 (0)