diff --git a/.github/workflows/R-CMD-check.yaml b/.github/workflows/R-CMD-check.yaml index 17efced74..b2a69e549 100644 --- a/.github/workflows/R-CMD-check.yaml +++ b/.github/workflows/R-CMD-check.yaml @@ -1,7 +1,10 @@ on: push: + branches: + - master pull_request: - types: [opened, synchronize, reopened] + branches: + - master name: R-CMD-check @@ -18,7 +21,7 @@ jobs: - {os: macOS-latest, r: 'release'} - {os: windows-latest, r: 'release'} - {os: windows-latest, r: '3.6'} - - {os: ubuntu-16.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} + - {os: ubuntu-16.04, r: 'devel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest", http-user-agent: "R/4.0.0 (ubuntu-16.04) R (4.0.0 x86_64-pc-linux-gnu x86_64 linux-gnu) on GitHub Actions" } - {os: ubuntu-16.04, r: 'release', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: 'oldrel', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} - {os: ubuntu-16.04, r: '3.5', rspm: "https://packagemanager.rstudio.com/cran/__linux__/xenial/latest"} @@ -34,6 +37,7 @@ jobs: - uses: r-lib/actions/setup-r@master with: r-version: ${{ matrix.config.r }} + http-user-agent: ${{ matrix.config.http-user-agent }} - uses: r-lib/actions/setup-pandoc@master @@ -79,7 +83,7 @@ jobs: run: | reticulate::conda_create('r-reticulate', packages = c('python==3.6.9')) tensorflow::install_tensorflow(version='1.14.0') - shell: Rscript {0} + shell: Rscript {0} - name: Session info run: | diff --git a/NAMESPACE b/NAMESPACE index d238df397..87169f197 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -168,6 +168,7 @@ export(set_model_mode) export(set_new_model) export(set_pred) export(show_call) +export(show_engines) export(show_fit) export(show_model_info) export(surv_reg) diff --git a/NEWS.md b/NEWS.md index 8a5fc3ef0..adb9b6db8 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # parsnip (development version) +* `show_engines()` will provide information on the current set for a model. + # parsnip 0.1.3 * A `glance()` method for `model_fit` objects was added (#325) diff --git a/R/boost_tree.R b/R/boost_tree.R index d3f1cc31d..a005dbb64 100644 --- a/R/boost_tree.R +++ b/R/boost_tree.R @@ -62,6 +62,8 @@ #' \item \pkg{Spark}: `"spark"` #' } #' +#' For this model, other packages may add additional engines. Use +#' [show_engines()] to see the current set of engines. #' #' @includeRmd man/rmd/boost-tree.Rmd details #' @@ -81,6 +83,8 @@ #' @importFrom purrr map_lgl #' @seealso [fit()], [set_engine()] #' @examples +#' show_engines("boost_tree") +#' #' boost_tree(mode = "classification", trees = 20) #' # Parameters can be represented by a placeholder: #' boost_tree(mode = "regression", mtry = varying()) diff --git a/R/decision_tree.R b/R/decision_tree.R index 5c518771f..015501971 100644 --- a/R/decision_tree.R +++ b/R/decision_tree.R @@ -62,6 +62,8 @@ #' @importFrom purrr map_lgl #' @seealso [fit()] #' @examples +#' show_engines("decision_tree") +#' #' decision_tree(mode = "classification", tree_depth = 5) #' # Parameters can be represented by a placeholder: #' decision_tree(mode = "regression", cost_complexity = varying()) diff --git a/R/engines.R b/R/engines.R index f1ad8a3ec..20593dc9e 100644 --- a/R/engines.R +++ b/R/engines.R @@ -106,3 +106,24 @@ set_engine <- function(object, engine, ...) { engine = object$engine ) } + +#' Display available engines for a model +#' +#' The possible engines for a model may depend on what packages are loaded. There +#' are some `parsnip`-adjacent packages that only add engines to existing models. +#' @param x The name of a `parsnip` model (e.g., "linear_reg", "mars", etc.) +#' @return A tibble. +#' show_engines("linear_reg") +#' @export +show_engines <- function(x) { + if (!is.character(x) || length(x) > 1) { + rlang::abort("`show_engines()` takes a single character string as input.") + } + res <- try(get_from_env(x), silent = TRUE) + if (inherits(res, "try-error")) { + rlang::abort( + paste0("No results found for model function '", x, "'.") + ) + } + res +} diff --git a/R/linear_reg.R b/R/linear_reg.R index 619a3c761..0839f4132 100644 --- a/R/linear_reg.R +++ b/R/linear_reg.R @@ -42,6 +42,9 @@ #' \item \pkg{keras}: `"keras"` #' } #' +#' For this model, other packages may add additional engines. Use +#' [show_engines()] to see the current set of engines. +#' #' @includeRmd man/rmd/linear-reg.Rmd details #' #' @note For models created using the spark engine, there are @@ -59,6 +62,8 @@ #' #' @seealso [fit()], [set_engine()] #' @examples +#' show_engines("linear_reg") +#' #' linear_reg() #' # Parameters can be represented by a placeholder: #' linear_reg(penalty = varying()) diff --git a/R/logistic_reg.R b/R/logistic_reg.R index 049a19685..c8bf93c6e 100644 --- a/R/logistic_reg.R +++ b/R/logistic_reg.R @@ -40,6 +40,9 @@ #' \item \pkg{keras}: `"keras"` #' } #' +#' For this model, other packages may add additional engines. Use +#' [show_engines()] to see the current set of engines. +#' #' @includeRmd man/rmd/logistic-reg.Rmd details #' #' @note For models created using the spark engine, there are @@ -57,6 +60,8 @@ #' #' @seealso [fit()] #' @examples +#' show_engines("logistic_reg") +#' #' logistic_reg() #' # Parameters can be represented by a placeholder: #' logistic_reg(penalty = varying()) diff --git a/R/mars.R b/R/mars.R index 1e68efb95..276ff82f7 100644 --- a/R/mars.R +++ b/R/mars.R @@ -41,6 +41,8 @@ #' @importFrom purrr map_lgl #' @seealso [fit()] #' @examples +#' show_engines("mars") +#' #' mars(mode = "regression", num_terms = 5) #' @export mars <- diff --git a/R/mlp.R b/R/mlp.R index 422e1fcd3..bee75a322 100644 --- a/R/mlp.R +++ b/R/mlp.R @@ -56,6 +56,8 @@ #' @importFrom purrr map_lgl #' @seealso [fit()] #' @examples +#' show_engines("mlp") +#' #' mlp(mode = "classification", penalty = 0.01) #' # Parameters can be represented by a placeholder: #' mlp(mode = "regression", hidden_units = varying()) diff --git a/R/multinom_reg.R b/R/multinom_reg.R index 48310ca48..1bcd4525b 100644 --- a/R/multinom_reg.R +++ b/R/multinom_reg.R @@ -56,6 +56,8 @@ #' #' @seealso [fit()] #' @examples +#' show_engines("multinom_reg") +#' #' multinom_reg() #' # Parameters can be represented by a placeholder: #' multinom_reg(penalty = varying()) diff --git a/R/nearest_neighbor.R b/R/nearest_neighbor.R index 6988697a6..37b953596 100644 --- a/R/nearest_neighbor.R +++ b/R/nearest_neighbor.R @@ -51,6 +51,8 @@ #' @seealso [fit()] #' #' @examples +#' show_engines("nearest_neighbor") +#' #' nearest_neighbor(neighbors = 11) #' #' @export diff --git a/R/rand_forest.R b/R/rand_forest.R index 98177eae5..1f018ec19 100644 --- a/R/rand_forest.R +++ b/R/rand_forest.R @@ -56,6 +56,8 @@ #' @importFrom purrr map_lgl #' @seealso [fit()] #' @examples +#' show_engines("rand_forest") +#' #' rand_forest(mode = "classification", trees = 2000) #' # Parameters can be represented by a placeholder: #' rand_forest(mode = "regression", mtry = varying()) diff --git a/R/surv_reg.R b/R/surv_reg.R index cced97abf..d775ff399 100644 --- a/R/surv_reg.R +++ b/R/surv_reg.R @@ -45,6 +45,8 @@ #' @references Jackson, C. (2016). `flexsurv`: A Platform for Parametric Survival #' Modeling in R. _Journal of Statistical Software_, 70(8), 1 - 33. #' @examples +#' show_engines("surv_reg") +#' #' surv_reg() #' # Parameters can be represented by a placeholder: #' surv_reg(dist = varying()) diff --git a/R/svm_poly.R b/R/svm_poly.R index 5edc8c631..087af9b79 100644 --- a/R/svm_poly.R +++ b/R/svm_poly.R @@ -41,6 +41,8 @@ #' @importFrom purrr map_lgl #' @seealso [fit()] #' @examples +#' show_engines("svm_poly") +#' #' svm_poly(mode = "classification", degree = 1.2) #' # Parameters can be represented by a placeholder: #' svm_poly(mode = "regression", cost = varying()) diff --git a/R/svm_rbf.R b/R/svm_rbf.R index 52503f72a..e64abee70 100644 --- a/R/svm_rbf.R +++ b/R/svm_rbf.R @@ -42,6 +42,8 @@ #' @importFrom purrr map_lgl #' @seealso [fit()] #' @examples +#' show_engines("svm_rbf") +#' #' svm_rbf(mode = "classification", rbf_sigma = 0.2) #' # Parameters can be represented by a placeholder: #' svm_rbf(mode = "regression", cost = varying()) diff --git a/man/boost_tree.Rd b/man/boost_tree.Rd index af7fbf2ff..d3904ca93 100644 --- a/man/boost_tree.Rd +++ b/man/boost_tree.Rd @@ -117,6 +117,9 @@ following \emph{engines}: \item \pkg{R}: \code{"xgboost"} (the default), \code{"C5.0"} \item \pkg{Spark}: \code{"spark"} } + +For this model, other packages may add additional engines. Use +\code{\link[=show_engines]{show_engines()}} to see the current set of engines. } \note{ For models created using the spark engine, there are @@ -178,6 +181,10 @@ mod_param <- update(sample_size = sample_prop(c(0.4, 0.9))) }\if{html}{\out{}} +For this engine, tuning over \code{trees} is very efficient since the same +model object can be used to make predictions over multiple values of +\code{trees}. + Finally, note that \code{xgboost} models require that non-numeric predictors (e.g., factors) must be converted to dummy variables or some other numeric representation. By default, when using \code{fit()} with \code{xgboost}, a @@ -201,6 +208,10 @@ Note that \code{\link[C50:C5.0]{C50::C5.0()}} does not require factor predictors to be converted to indicator variables. \code{fit()} does not affect the encoding of the predictor values (i.e. factors stay factors) for this model. + +For this engine, tuning over \code{trees} is very efficient since the same +model object can be used to make predictions over multiple values of +\code{trees}. } \subsection{spark}{\if{html}{\out{