diff --git a/man/details_bag_tree_C5.0.Rd b/man/details_bag_tree_C5.0.Rd index a1b62199d..aea3b8037 100644 --- a/man/details_bag_tree_C5.0.Rd +++ b/man/details_bag_tree_C5.0.Rd @@ -63,13 +63,16 @@ The \code{fit()} and \code{fit_xy()} functions have arguments called \subsection{Prediction types}{ -\if{html}{\out{
}}\preformatted{parsnip:::get_from_env("bag_mars_predict") |> +\if{html}{\out{
}}\preformatted{parsnip:::get_from_env("bag_tree_predict") |> dplyr::filter(engine == "C5.0") |> dplyr::select(mode, type) }\if{html}{\out{
}} -\if{html}{\out{
}}\preformatted{## # A tibble: 0 x 2 -## # i 2 variables: mode , type +\if{html}{\out{
}}\preformatted{## # A tibble: 2 x 2 +## mode type +## +## 1 classification class +## 2 classification prob }\if{html}{\out{
}} } diff --git a/man/details_bag_tree_rpart.Rd b/man/details_bag_tree_rpart.Rd index fa47101de..917eac8a2 100644 --- a/man/details_bag_tree_rpart.Rd +++ b/man/details_bag_tree_rpart.Rd @@ -153,13 +153,19 @@ The underlying model implementation does not allow for case weights. \subsection{Prediction types}{ -\if{html}{\out{
}}\preformatted{parsnip:::get_from_env("bag_mars_predict") |> +\if{html}{\out{
}}\preformatted{parsnip:::get_from_env("bag_tree_predict") |> dplyr::filter(engine == "rpart") |> dplyr::select(mode, type) }\if{html}{\out{
}} -\if{html}{\out{
}}\preformatted{## # A tibble: 0 x 2 -## # i 2 variables: mode , type +\if{html}{\out{
}}\preformatted{## # A tibble: 5 x 2 +## mode type +## +## 1 regression numeric +## 2 classification class +## 3 classification prob +## 4 censored regression time +## 5 censored regression survival }\if{html}{\out{
}} } diff --git a/man/details_ordinal_reg_polr.Rd b/man/details_ordinal_reg_polr.Rd index 3b596e114..67b97ce91 100644 --- a/man/details_ordinal_reg_polr.Rd +++ b/man/details_ordinal_reg_polr.Rd @@ -34,6 +34,21 @@ ordinal_reg() \%>\% }\if{html}{\out{
}} } +\subsection{Prediction types}{ + +\if{html}{\out{
}}\preformatted{parsnip:::get_from_env("ordinal_reg_predict") |> + dplyr::filter(engine == "polr") |> + dplyr::select(mode, type) +}\if{html}{\out{
}} + +\if{html}{\out{
}}\preformatted{## # A tibble: 2 x 2 +## mode type +## +## 1 classification class +## 2 classification prob +}\if{html}{\out{
}} +} + \subsection{References}{ \itemize{ \item Bürkner P-C, Vuorre M. 2019. Ordinal Regression Models in Psychology: diff --git a/man/details_rand_forest_grf.Rd b/man/details_rand_forest_grf.Rd index 3f65e356f..52cf23f45 100644 --- a/man/details_rand_forest_grf.Rd +++ b/man/details_rand_forest_grf.Rd @@ -161,6 +161,25 @@ The “Fitting and Predicting with parsnip” contains examples for \code{rand_forest()} with the \code{"grf"} engine. } +\subsection{Prediction types}{ + +\if{html}{\out{
}}\preformatted{parsnip:::get_from_env("rand_forest_predict") |> + dplyr::filter(engine == "grf") |> + dplyr::select(mode, type) +}\if{html}{\out{
}} + +\if{html}{\out{
}}\preformatted{## # A tibble: 6 x 2 +## mode type +## +## 1 classification class +## 2 classification prob +## 3 classification conf_int +## 4 regression numeric +## 5 regression conf_int +## 6 quantile regression quantile +}\if{html}{\out{
}} +} + \subsection{References}{ Athey, Susan, Julie Tibshirani, and Stefan Wager. “Generalized Random diff --git a/man/details_rand_forest_ordinalForest.Rd b/man/details_rand_forest_ordinalForest.Rd index 462fa6f01..b539d5320 100644 --- a/man/details_rand_forest_ordinalForest.Rd +++ b/man/details_rand_forest_ordinalForest.Rd @@ -83,6 +83,21 @@ parallelize the construction of the trees within the model, change the \code{num.threads} argument via \code{\link[=set_engine]{set_engine()}}. } +\subsection{Prediction types}{ + +\if{html}{\out{
}}\preformatted{parsnip:::get_from_env("rand_forest_predict") |> + dplyr::filter(engine == "ordinalForest") |> + dplyr::select(mode, type) +}\if{html}{\out{
}} + +\if{html}{\out{
}}\preformatted{## # A tibble: 2 x 2 +## mode type +## +## 1 classification class +## 2 classification prob +}\if{html}{\out{
}} +} + \subsection{References}{ \itemize{ \item Hornung R. 2020. Ordinal Forests. \emph{Journal of Classification} 37:4-17. diff --git a/man/details_svm_rbf_kernlab.Rd b/man/details_svm_rbf_kernlab.Rd index f21564609..cc932455f 100644 --- a/man/details_svm_rbf_kernlab.Rd +++ b/man/details_svm_rbf_kernlab.Rd @@ -111,23 +111,19 @@ The underlying model implementation does not allow for case weights. \subsection{Prediction types}{ \if{html}{\out{
}}\preformatted{parsnip:::get_from_env("svm_rbf_predict") |> + dplyr::filter(engine == "kernlab") |> dplyr::select(mode, type) |> print(n = Inf) }\if{html}{\out{
}} -\if{html}{\out{
}}\preformatted{## # A tibble: 10 x 2 -## mode type -## -## 1 regression numeric -## 2 regression raw -## 3 classification class -## 4 classification prob -## 5 classification raw -## 6 regression numeric -## 7 regression raw -## 8 classification class -## 9 classification prob -## 10 classification raw +\if{html}{\out{
}}\preformatted{## # A tibble: 5 x 2 +## mode type +## +## 1 regression numeric +## 2 regression raw +## 3 classification class +## 4 classification prob +## 5 classification raw }\if{html}{\out{
}} } diff --git a/man/null_model.Rd b/man/null_model.Rd index 7f2f6e8f9..9c658314d 100644 --- a/man/null_model.Rd +++ b/man/null_model.Rd @@ -65,19 +65,18 @@ call. For this type of model, the template of the fit calls are below: \subsection{Prediction types}{ \if{html}{\out{
}}\preformatted{parsnip:::get_from_env("null_model_predict") |> + dplyr::filter(engine == "parsnip") |> dplyr::select(mode, type) }\if{html}{\out{
}} -\if{html}{\out{
}}\preformatted{## # A tibble: 7 x 2 -## mode type -## -## 1 regression numeric -## 2 regression raw -## 3 classification class -## 4 classification prob -## 5 classification raw -## 6 censored regression time -## # i 1 more row +\if{html}{\out{
}}\preformatted{## # A tibble: 5 x 2 +## mode type +## +## 1 regression numeric +## 2 regression raw +## 3 classification class +## 4 classification prob +## 5 classification raw }\if{html}{\out{
}} } } diff --git a/man/rmd/bag_tree_C5.0.Rmd b/man/rmd/bag_tree_C5.0.Rmd index ce52ab61a..cd99c570d 100644 --- a/man/rmd/bag_tree_C5.0.Rmd +++ b/man/rmd/bag_tree_C5.0.Rmd @@ -61,7 +61,7 @@ bag_tree(min_n = integer()) |> ```{r} #| label: predict-types -parsnip:::get_from_env("bag_mars_predict") |> +parsnip:::get_from_env("bag_tree_predict") |> dplyr::filter(engine == "C5.0") |> dplyr::select(mode, type) @@ -72,4 +72,3 @@ parsnip:::get_from_env("bag_mars_predict") |> - Breiman, L. 1996. "Bagging predictors". Machine Learning. 24 (2): 123-140 - Kuhn, M, and K Johnson. 2013. *Applied Predictive Modeling*. Springer. - diff --git a/man/rmd/bag_tree_C5.0.md b/man/rmd/bag_tree_C5.0.md index a1dfecb13..83de005aa 100644 --- a/man/rmd/bag_tree_C5.0.md +++ b/man/rmd/bag_tree_C5.0.md @@ -55,14 +55,17 @@ The `fit()` and `fit_xy()` functions have arguments called `case_weights` that e ``` r -parsnip:::get_from_env("bag_mars_predict") |> +parsnip:::get_from_env("bag_tree_predict") |> dplyr::filter(engine == "C5.0") |> dplyr::select(mode, type) ``` ``` -## # A tibble: 0 x 2 -## # i 2 variables: mode , type +## # A tibble: 2 x 2 +## mode type +## +## 1 classification class +## 2 classification prob ``` ## References @@ -70,4 +73,3 @@ parsnip:::get_from_env("bag_mars_predict") |> - Breiman, L. 1996. "Bagging predictors". Machine Learning. 24 (2): 123-140 - Kuhn, M, and K Johnson. 2013. *Applied Predictive Modeling*. Springer. - diff --git a/man/rmd/bag_tree_rpart.Rmd b/man/rmd/bag_tree_rpart.Rmd index 41c840b82..65ecdea43 100644 --- a/man/rmd/bag_tree_rpart.Rmd +++ b/man/rmd/bag_tree_rpart.Rmd @@ -115,7 +115,7 @@ bag_tree( ```{r} #| label: predict-types -parsnip:::get_from_env("bag_mars_predict") |> +parsnip:::get_from_env("bag_tree_predict") |> dplyr::filter(engine == "rpart") |> dplyr::select(mode, type) ``` diff --git a/man/rmd/bag_tree_rpart.md b/man/rmd/bag_tree_rpart.md index 7b6a8d942..eb4c45998 100644 --- a/man/rmd/bag_tree_rpart.md +++ b/man/rmd/bag_tree_rpart.md @@ -147,14 +147,20 @@ The underlying model implementation does not allow for case weights. ``` r -parsnip:::get_from_env("bag_mars_predict") |> +parsnip:::get_from_env("bag_tree_predict") |> dplyr::filter(engine == "rpart") |> dplyr::select(mode, type) ``` ``` -## # A tibble: 0 x 2 -## # i 2 variables: mode , type +## # A tibble: 5 x 2 +## mode type +## +## 1 regression numeric +## 2 classification class +## 3 classification prob +## 4 censored regression time +## 5 censored regression survival ``` ## Other details diff --git a/man/rmd/null-model.Rmd b/man/rmd/null-model.Rmd index d7f681988..20dc2e75a 100644 --- a/man/rmd/null-model.Rmd +++ b/man/rmd/null-model.Rmd @@ -27,6 +27,7 @@ null_model() |> #| label: predict-types parsnip:::get_from_env("null_model_predict") |> + dplyr::filter(engine == "parsnip") |> dplyr::select(mode, type) -``` \ No newline at end of file +``` diff --git a/man/rmd/null-model.md b/man/rmd/null-model.md index 0e402d5b0..988df9f3d 100644 --- a/man/rmd/null-model.md +++ b/man/rmd/null-model.md @@ -44,18 +44,17 @@ null_model() |> ``` r parsnip:::get_from_env("null_model_predict") |> + dplyr::filter(engine == "parsnip") |> dplyr::select(mode, type) ``` ``` -## # A tibble: 7 x 2 -## mode type -## -## 1 regression numeric -## 2 regression raw -## 3 classification class -## 4 classification prob -## 5 classification raw -## 6 censored regression time -## # i 1 more row +## # A tibble: 5 x 2 +## mode type +## +## 1 regression numeric +## 2 regression raw +## 3 classification class +## 4 classification prob +## 5 classification raw ``` diff --git a/man/rmd/ordinal_reg_polr.Rmd b/man/rmd/ordinal_reg_polr.Rmd index e8a639ab5..df11c54df 100644 --- a/man/rmd/ordinal_reg_polr.Rmd +++ b/man/rmd/ordinal_reg_polr.Rmd @@ -20,6 +20,15 @@ ordinal_reg() %>% translate() ``` +## Prediction types + +```{r} +#| label: predict-types +parsnip:::get_from_env("ordinal_reg_predict") |> + dplyr::filter(engine == "polr") |> + dplyr::select(mode, type) +``` + ## References - Bürkner P-C, Vuorre M. 2019. Ordinal Regression Models in Psychology: A Tutorial. _Advances in Methods and Practices in Psychological Science_ 2(1):77-101. \doi{10.1177/2515245918823199}. diff --git a/man/rmd/ordinal_reg_polr.md b/man/rmd/ordinal_reg_polr.md index 6c8737be2..2a22057e2 100644 --- a/man/rmd/ordinal_reg_polr.md +++ b/man/rmd/ordinal_reg_polr.md @@ -30,6 +30,23 @@ ordinal_reg() %>% ## MASS::polr(formula = missing_arg(), data = missing_arg(), weights = missing_arg()) ``` +## Prediction types + + +``` r +parsnip:::get_from_env("ordinal_reg_predict") |> + dplyr::filter(engine == "polr") |> + dplyr::select(mode, type) +``` + +``` +## # A tibble: 2 x 2 +## mode type +## +## 1 classification class +## 2 classification prob +``` + ## References - Bürkner P-C, Vuorre M. 2019. Ordinal Regression Models in Psychology: A Tutorial. _Advances in Methods and Practices in Psychological Science_ 2(1):77-101. \doi{10.1177/2515245918823199}. diff --git a/man/rmd/ordinal_reg_vglm.Rmd b/man/rmd/ordinal_reg_vglm.Rmd index 1b5c6b995..09106c79b 100644 --- a/man/rmd/ordinal_reg_vglm.Rmd +++ b/man/rmd/ordinal_reg_vglm.Rmd @@ -14,7 +14,7 @@ defaults <- param <- ordinal_reg() |> - set_engine("ordinalNet") |> + set_engine("vglm") |> set_mode("classification") |> make_parameter_list(defaults) ``` diff --git a/man/rmd/rand_forest_grf.Rmd b/man/rmd/rand_forest_grf.Rmd index 6dfbff867..7e0a08c47 100644 --- a/man/rmd/rand_forest_grf.Rmd +++ b/man/rmd/rand_forest_grf.Rmd @@ -101,7 +101,15 @@ The regression and classification models enable the use of case weights. The qua The "Fitting and Predicting with parsnip" [article](https://www.tidymodels.org/learn/models/parsnip-predictions/) contains examples for `rand_forest()` with the `"grf"` engine. +## Prediction types + +```{r} +#| label: predict-types +parsnip:::get_from_env("rand_forest_predict") |> + dplyr::filter(engine == "grf") |> + dplyr::select(mode, type) +``` + ## References Athey, Susan, Julie Tibshirani, and Stefan Wager. "Generalized Random Forests". _Annals of Statistics_, 47(2), 2019. - diff --git a/man/rmd/rand_forest_grf.md b/man/rmd/rand_forest_grf.md index 860667080..754f021d1 100644 --- a/man/rmd/rand_forest_grf.md +++ b/man/rmd/rand_forest_grf.md @@ -141,7 +141,27 @@ The regression and classification models enable the use of case weights. The qua The "Fitting and Predicting with parsnip" [article](https://www.tidymodels.org/learn/models/parsnip-predictions/) contains examples for `rand_forest()` with the `"grf"` engine. +## Prediction types + + +``` r +parsnip:::get_from_env("rand_forest_predict") |> + dplyr::filter(engine == "grf") |> + dplyr::select(mode, type) +``` + +``` +## # A tibble: 6 x 2 +## mode type +## +## 1 classification class +## 2 classification prob +## 3 classification conf_int +## 4 regression numeric +## 5 regression conf_int +## 6 quantile regression quantile +``` + ## References Athey, Susan, Julie Tibshirani, and Stefan Wager. "Generalized Random Forests". _Annals of Statistics_, 47(2), 2019. - diff --git a/man/rmd/rand_forest_ordinalForest.Rmd b/man/rmd/rand_forest_ordinalForest.Rmd index d12cfdd97..1345a1ea8 100644 --- a/man/rmd/rand_forest_ordinalForest.Rmd +++ b/man/rmd/rand_forest_ordinalForest.Rmd @@ -57,6 +57,15 @@ rand_forest( By default, parallel processing is turned off. When tuning, it is more efficient to parallelize over the resamples and tuning parameters. To parallelize the construction of the trees within the model, change the `num.threads` argument via [set_engine()]. +## Prediction types + +```{r} +#| label: predict-types +parsnip:::get_from_env("rand_forest_predict") |> + dplyr::filter(engine == "ordinalForest") |> + dplyr::select(mode, type) +``` + ## References - Hornung R. 2020. Ordinal Forests. _Journal of Classification_ 37:4-17. \doi{10.1007/s00357-018-9302-x}. diff --git a/man/rmd/rand_forest_ordinalForest.md b/man/rmd/rand_forest_ordinalForest.md index 61a863baa..3250a9c5f 100644 --- a/man/rmd/rand_forest_ordinalForest.md +++ b/man/rmd/rand_forest_ordinalForest.md @@ -66,6 +66,23 @@ The `fit()` and `fit_xy()` functions have arguments called `case_weights` that e By default, parallel processing is turned off. When tuning, it is more efficient to parallelize over the resamples and tuning parameters. To parallelize the construction of the trees within the model, change the `num.threads` argument via [set_engine()]. +## Prediction types + + +``` r +parsnip:::get_from_env("rand_forest_predict") |> + dplyr::filter(engine == "ordinalForest") |> + dplyr::select(mode, type) +``` + +``` +## # A tibble: 2 x 2 +## mode type +## +## 1 classification class +## 2 classification prob +``` + ## References - Hornung R. 2020. Ordinal Forests. _Journal of Classification_ 37:4-17. \doi{10.1007/s00357-018-9302-x}. diff --git a/man/rmd/svm_rbf_kernlab.Rmd b/man/rmd/svm_rbf_kernlab.Rmd index 6b4248d34..4a7773517 100644 --- a/man/rmd/svm_rbf_kernlab.Rmd +++ b/man/rmd/svm_rbf_kernlab.Rmd @@ -86,6 +86,7 @@ Note that the `"kernlab"` engine does not naturally estimate class probabilities #| label: predict-types parsnip:::get_from_env("svm_rbf_predict") |> + dplyr::filter(engine == "kernlab") |> dplyr::select(mode, type) |> print(n = Inf) @@ -108,4 +109,3 @@ The "Fitting and Predicting with parsnip" [article](https://www.tidymodels.org/l - Karatzoglou, A, Smola, A, Hornik, K, and A Zeileis. 2004. ["kernlab - An S4 Package for Kernel Methods in R."](https://www.jstatsoft.org/article/view/v011i09), _Journal of Statistical Software_. - Kuhn, M, and K Johnson. 2013. _Applied Predictive Modeling_. Springer. - diff --git a/man/rmd/svm_rbf_kernlab.md b/man/rmd/svm_rbf_kernlab.md index 8a241b353..2d0bc9830 100644 --- a/man/rmd/svm_rbf_kernlab.md +++ b/man/rmd/svm_rbf_kernlab.md @@ -98,24 +98,20 @@ The underlying model implementation does not allow for case weights. ``` r parsnip:::get_from_env("svm_rbf_predict") |> + dplyr::filter(engine == "kernlab") |> dplyr::select(mode, type) |> print(n = Inf) ``` ``` -## # A tibble: 10 x 2 -## mode type -## -## 1 regression numeric -## 2 regression raw -## 3 classification class -## 4 classification prob -## 5 classification raw -## 6 regression numeric -## 7 regression raw -## 8 classification class -## 9 classification prob -## 10 classification raw +## # A tibble: 5 x 2 +## mode type +## +## 1 regression numeric +## 2 regression raw +## 3 classification class +## 4 classification prob +## 5 classification raw ``` ## Saving fitted model objects @@ -134,4 +130,3 @@ The "Fitting and Predicting with parsnip" [article](https://www.tidymodels.org/l - Karatzoglou, A, Smola, A, Hornik, K, and A Zeileis. 2004. ["kernlab - An S4 Package for Kernel Methods in R."](https://www.jstatsoft.org/article/view/v011i09), _Journal of Statistical Software_. - Kuhn, M, and K Johnson. 2013. _Applied Predictive Modeling_. Springer. - diff --git a/tests/testthat/_snaps/boost_tree_xgboost.md b/tests/testthat/_snaps/boost_tree_xgboost.md index 5f1b9b544..c715e9e73 100644 --- a/tests/testthat/_snaps/boost_tree_xgboost.md +++ b/tests/testthat/_snaps/boost_tree_xgboost.md @@ -140,11 +140,11 @@ evaluation_log: iter validation_quantile - 1 7.009181 - 2 6.548682 + 1 7.281056 + 2 6.935199 --- --- - 49 5.314723 - 50 5.304116 + 49 5.021312 + 50 5.012909 --- @@ -181,7 +181,7 @@ 0.9)), data = x$data, nrounds = 50, evals = x$watchlist, verbose = 0, early_stopping_rounds = 2) # of features: 20 - # of rounds: 42 + # of rounds: 50 xgb.attributes: best_iteration, best_score callbacks: @@ -189,9 +189,9 @@ evaluation_log: iter validation_quantile - 1 7.009181 - 2 6.548682 + 1 7.281056 + 2 6.935199 --- --- - 41 5.339619 - 42 5.342320 + 49 5.021312 + 50 5.012909 diff --git a/tests/testthat/test-boost_tree_xgboost.R b/tests/testthat/test-boost_tree_xgboost.R index 77b0a14f1..e7a63a49d 100644 --- a/tests/testthat/test-boost_tree_xgboost.R +++ b/tests/testthat/test-boost_tree_xgboost.R @@ -939,7 +939,7 @@ test_that('interface to param arguments', { test_that('xgboost execution, quantile regression', { skip_if(getRversion() <= "4.2.3") - skip_if_not_installed("xgboost") + skip_if_not_installed("xgboost", minimum_version = "3.4.0.0") skip_if_not_installed("modeldata") skip_on_cran() diff --git a/tests/testthat/test-engine-docs.R b/tests/testthat/test-engine-docs.R new file mode 100644 index 000000000..3b4d2dce8 --- /dev/null +++ b/tests/testthat/test-engine-docs.R @@ -0,0 +1,174 @@ +extract_engine_doc_match <- function(pattern, text) { + match <- regexec(pattern, text, perl = TRUE) + values <- regmatches(text, match)[[1]] + if (length(values) == 0) { + return(NULL) + } + values[-1] +} + +prediction_doc_chunk <- function(lines) { + labels <- grep("^#\\| label: predict-types\\s*$", lines) + if (length(labels) != 1) { + return(NULL) + } + + closing_fence <- grep("^```\\s*$", lines[(labels + 1):length(lines)]) + if (length(closing_fence) == 0) { + return(NULL) + } + + end <- labels + closing_fence[[1]] - 1 + paste(lines[labels:end], collapse = "\n") +} + +prediction_doc_output <- function(lines) { + heading <- which(lines == "## Prediction types") + if (length(heading) != 1) { + return(NULL) + } + + next_heading <- grep("^## [^#]", lines[(heading + 1):length(lines)]) + if (length(next_heading) == 0) { + end <- length(lines) + } else { + end <- heading + next_heading[[1]] - 1 + } + + paste(lines[heading:end], collapse = "\n") +} + +test_that("engine documentation uses matching prediction registrations", { + rmd_dir <- test_path("..", "..", "man", "rmd") + model_info <- model_info_table + rmd_files <- list.files(rmd_dir, pattern = "\\.Rmd$", full.names = TRUE) + problems <- character() + + for (rmd_file in rmd_files) { + lines <- readLines(rmd_file, warn = FALSE) + text <- paste(lines, collapse = "\n") + declared <- extract_engine_doc_match( + 'descr_models\\("([^"]+)",\\s*"([^"]+)"\\)', + text + ) + + if (is.null(declared) && basename(rmd_file) != "null-model.Rmd") { + next + } + + if (basename(rmd_file) == "null-model.Rmd") { + declared <- c("null_model", "parsnip") + } + + parameter_list <- regexpr("make_parameter_list\\(", text) + if (parameter_list[[1]] != -1) { + parameter_setup <- substr(text, 1, parameter_list[[1]]) + parameter_engine <- extract_engine_doc_match( + 'set_engine\\("([^"]+)"', + parameter_setup + ) + if ( + is.null(parameter_engine) || + parameter_engine[[1]] != declared[[2]] + ) { + problems <- c( + problems, + paste0( + basename(rmd_file), + " uses engine ", + if (is.null(parameter_engine)) "none" else parameter_engine[[1]], + " for its parameter list; expected ", + declared[[2]], + "." + ) + ) + } + } + + chunk <- prediction_doc_chunk(lines) + if (is.null(chunk)) { + problems <- c( + problems, + paste0(basename(rmd_file), " must have one prediction-types chunk.") + ) + next + } + + registry <- extract_engine_doc_match( + 'get_from_env\\("([^"]+)_predict"\\)', + chunk + ) + if (is.null(registry) || registry[[1]] != declared[[1]]) { + problems <- c( + problems, + paste0( + basename(rmd_file), + " queries ", + if (is.null(registry)) "no prediction registry" else registry[[1]], + "; expected ", + declared[[1]], + "." + ) + ) + } + + engine <- extract_engine_doc_match('engine\\s*==\\s*"([^"]+)"', chunk) + if (is.null(engine)) { + engine <- extract_engine_doc_match( + 'str_starts\\(engine,\\s*"([^"]+)"', + chunk + ) + } + + known_engines <- unique(model_info$engine[ + model_info$model == declared[[1]] + ]) + if (length(known_engines) > 1 && is.null(engine)) { + problems <- c( + problems, + paste0( + basename(rmd_file), + " must filter prediction types to engine ", + declared[[2]], + "." + ) + ) + } else if (!is.null(engine) && engine[[1]] != declared[[2]]) { + problems <- c( + problems, + paste0( + basename(rmd_file), + " filters engine ", + engine[[1]], + "; expected ", + declared[[2]], + "." + ) + ) + } + + md_file <- sub("\\.Rmd$", ".md", rmd_file) + if (!file.exists(md_file)) { + problems <- c( + problems, + paste0(basename(md_file), " has not been generated.") + ) + next + } + + output <- prediction_doc_output(readLines(md_file, warn = FALSE)) + if (is.null(output)) { + problems <- c( + problems, + paste0(basename(md_file), " has no generated prediction section.") + ) + } else if (grepl("A tibble: 0 (x|×)", output)) { + problems <- c( + problems, + paste0(basename(md_file), " contains an empty prediction table.") + ) + } + } + + expect_identical(problems, character()) +})