diff --git a/DESCRIPTION b/DESCRIPTION index 412f4be..9879fca 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -22,7 +22,6 @@ Imports: C50, dials, dplyr, - earth, furrr, generics, hardhat (>= 1.1.0), @@ -38,6 +37,7 @@ Imports: Suggests: AmesHousing, covr, + earth, modeldata, nnet, recipes, @@ -50,4 +50,4 @@ Config/testthat/edition: 3 Encoding: UTF-8 Language: en-US Roxygen: list(markdown = TRUE) -RoxygenNote: 7.2.3 +RoxygenNote: 7.3.1 diff --git a/NAMESPACE b/NAMESPACE index d191e7a..d9d626c 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -23,8 +23,6 @@ importFrom(C50,C5.0Control) importFrom(C50,C5imp) importFrom(C50,as.party.C5.0) importFrom(dials,new_quant_param) -importFrom(earth,earth) -importFrom(earth,evimp) importFrom(furrr,future_map) importFrom(furrr,future_map2) importFrom(generics,var_imp) diff --git a/NEWS.md b/NEWS.md index 99e1f2a..468d78b 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,5 +1,7 @@ # baguette (development version) +* Move the earth package to Suggests due to CRAN note about the TeachingDemos (#71). + # baguette 1.0.1 * Added a `"nnet"` method for `bagger()`. diff --git a/R/aaa.R b/R/aaa.R index a88dacb..dc2d4d4 100644 --- a/R/aaa.R +++ b/R/aaa.R @@ -7,7 +7,6 @@ #' @importFrom parsnip new_model_spec null_value update_main_parameters #' @importFrom parsnip check_final_param model_printer show_call #' @importFrom utils globalVariables -#' @importFrom earth earth evimp #' @importFrom rsample analysis bootstraps assessment #' @importFrom purrr map map2 map_df map_dfr map_lgl #' @importFrom tibble tibble as_tibble is_tibble diff --git a/R/bagger.R b/R/bagger.R index 2788888..84feed4 100644 --- a/R/bagger.R +++ b/R/bagger.R @@ -67,11 +67,6 @@ #' #' # `times` is low to make the examples run faster #' -#' set.seed(7687) -#' mars_bag <- bagger(x = biomass_tr[, -6], y = biomass_tr$HHV, -#' base_model = "MARS", times = 5, control = ctrl) -#' mars_bag -#' var_imp(mars_bag) #' #' set.seed(7687) #' cart_bag <- bagger(x = biomass_tr[, -6], y = biomass_tr$HHV, @@ -92,10 +87,6 @@ #' #' cart_pca_bag #' -#' # Using formulas -#' mars_bag <- bagger(HHV ~ ., data = biomass_tr, base_model = "MARS", times = 5, -#' control = ctrl) -#' mars_bag #' @export bagger <- function(x, ...) { UseMethod("bagger") diff --git a/R/mars.R b/R/mars.R index c7a13b9..ff871ea 100644 --- a/R/mars.R +++ b/R/mars.R @@ -100,7 +100,10 @@ mars_fit <- function(split, spec, control = control_bag()) { } mars_imp <- function(x) { - imps <- earth::evimp(x$fit) + # see issue 71 + rlang::check_installed("earth") + cl <- rlang::call2("evimp", .ns = "earth", object = quote(x$fit)) + imps <- rlang::eval_tidy(cl) imps <- imps[, "gcv", drop = FALSE] x <- tibble::tibble(predictor = rownames(imps), importance = unname(imps[, "gcv"])) x <- x[x$importance > 0,] diff --git a/R/predict.R b/R/predict.R index 4cd4ee3..5e85ec3 100644 --- a/R/predict.R +++ b/R/predict.R @@ -15,8 +15,8 @@ #' data(airquality) #' #' set.seed(7687) -#' mars_bag <- bagger(Ozone ~ ., data = airquality, base_model = "MARS", times = 5) -#' predict(mars_bag, new_data = airquality[, -1]) +#' cart_bag <- bagger(Ozone ~ ., data = airquality, base_model = "CART", times = 5) +#' predict(cart_bag, new_data = airquality[, -1]) #' @export predict.bagger <- function(object, new_data, type = NULL, ...) { type <- check_type(object, type) diff --git a/inst/WORDLIST b/inst/WORDLIST index 19ee16b..39ff1a1 100644 --- a/inst/WORDLIST +++ b/inst/WORDLIST @@ -8,6 +8,7 @@ Lifecycle Modelling ORCID PBC +TeachingDemos al doi et diff --git a/man/bagger.Rd b/man/bagger.Rd index a0e66d5..5018b90 100644 --- a/man/bagger.Rd +++ b/man/bagger.Rd @@ -133,11 +133,6 @@ ctrl <- control_bag(var_imp = TRUE) # `times` is low to make the examples run faster -set.seed(7687) -mars_bag <- bagger(x = biomass_tr[, -6], y = biomass_tr$HHV, - base_model = "MARS", times = 5, control = ctrl) -mars_bag -var_imp(mars_bag) set.seed(7687) cart_bag <- bagger(x = biomass_tr[, -6], y = biomass_tr$HHV, @@ -158,10 +153,6 @@ cart_pca_bag <- bagger(biomass_rec, data = biomass_tr, base_model = "CART", cart_pca_bag -# Using formulas -mars_bag <- bagger(HHV ~ ., data = biomass_tr, base_model = "MARS", times = 5, - control = ctrl) -mars_bag } \references{ Gevrey, M., Dimopoulos, I., and Lek, S. (2003). Review and diff --git a/man/predict.bagger.Rd b/man/predict.bagger.Rd index fdbf94a..467fd01 100644 --- a/man/predict.bagger.Rd +++ b/man/predict.bagger.Rd @@ -28,6 +28,6 @@ for each sample in \code{new_data}. data(airquality) set.seed(7687) -mars_bag <- bagger(Ozone ~ ., data = airquality, base_model = "MARS", times = 5) -predict(mars_bag, new_data = airquality[, -1]) +cart_bag <- bagger(Ozone ~ ., data = airquality, base_model = "CART", times = 5) +predict(cart_bag, new_data = airquality[, -1]) } diff --git a/tests/testthat/test-interfaces.R b/tests/testthat/test-interfaces.R index 00f1106..b6c4f79 100644 --- a/tests/testthat/test-interfaces.R +++ b/tests/testthat/test-interfaces.R @@ -28,6 +28,7 @@ test_that('recipe execution', { # ------------------------------------------------------------------------------ test_that('var_imp', { + skip_if_not_installed("earth") mod <- bagger(mpg ~ ., data = mtcars, base_model = "MARS", times = 2) expect_true(tibble::is_tibble(var_imp(mod))) expect_equal(names(var_imp(mod)), c("term", "value", "std.error", "used")) diff --git a/tests/testthat/test-mars.R b/tests/testthat/test-mars.R index 3272a13..26f9e45 100644 --- a/tests/testthat/test-mars.R +++ b/tests/testthat/test-mars.R @@ -1,4 +1,5 @@ test_that('check mars opt', { + skip_if_not_installed("earth") set.seed(36323) check_pruning <- function(x, ...) { rlang::eval_tidy(x$call$pmethod) == "backward" @@ -57,6 +58,7 @@ test_that('check mars opt', { # ------------------------------------------------------------------------------ test_that('check model reduction', { + skip_if_not_installed("earth") set.seed(36323) reduced <- bagger( @@ -88,6 +90,7 @@ test_that('check model reduction', { # ------------------------------------------------------------------------------ test_that('check MARS parsnip interface', { + skip_if_not_installed("earth") set.seed(4779) expect_error( reg_mod <- bag_mars(num_terms = 5, prod_degree = 2) %>% @@ -149,6 +152,7 @@ test_that('check MARS parsnip interface', { }) test_that('mode specific package dependencies', { + skip_if_not_installed("earth") expect_identical( get_from_env(paste0("bag_mars", "_pkgs")) %>% dplyr::filter(engine == "earth", mode == "classification") %>% @@ -167,6 +171,7 @@ test_that('mode specific package dependencies', { test_that('case weights', { + skip_if_not_installed("earth") set.seed(1) wts <- runif(nrow(mtcars)) diff --git a/tests/testthat/test-validation.R b/tests/testthat/test-validation.R index 5851dab..ea8e505 100644 --- a/tests/testthat/test-validation.R +++ b/tests/testthat/test-validation.R @@ -87,6 +87,7 @@ test_that('validate imps', { # ------------------------------------------------------------------------------ test_that('bad inputs', { + skip_if_not_installed("earth") expect_error( bagger(mpg ~ ., data = mtcars, base_model = letters[1:2]), "should be a single character value."