Skip to content

Commit

Permalink
Changes for #71
Browse files Browse the repository at this point in the history
  • Loading branch information
‘topepo’ committed Feb 13, 2024
1 parent 6c23e76 commit 2dd7bff
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 28 deletions.
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ Imports:
C50,
dials,
dplyr,
earth,
furrr,
generics,
hardhat (>= 1.1.0),
Expand All @@ -38,6 +37,7 @@ Imports:
Suggests:
AmesHousing,
covr,
earth,
modeldata,
nnet,
recipes,
Expand All @@ -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
2 changes: 0 additions & 2 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -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()`.
Expand Down
1 change: 0 additions & 1 deletion R/aaa.R
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 0 additions & 9 deletions R/bagger.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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")
Expand Down
5 changes: 4 additions & 1 deletion R/mars.R
Original file line number Diff line number Diff line change
Expand Up @@ -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,]
Expand Down
4 changes: 2 additions & 2 deletions R/predict.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions inst/WORDLIST
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Lifecycle
Modelling
ORCID
PBC
TeachingDemos
al
doi
et
Expand Down
9 changes: 0 additions & 9 deletions man/bagger.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions man/predict.bagger.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tests/testthat/test-interfaces.R
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
Expand Down
5 changes: 5 additions & 0 deletions tests/testthat/test-mars.R
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -57,6 +58,7 @@ test_that('check mars opt', {
# ------------------------------------------------------------------------------

test_that('check model reduction', {
skip_if_not_installed("earth")
set.seed(36323)
reduced <-
bagger(
Expand Down Expand Up @@ -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) %>%
Expand Down Expand Up @@ -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") %>%
Expand All @@ -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))

Expand Down
1 change: 1 addition & 0 deletions tests/testthat/test-validation.R
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit 2dd7bff

Please sign in to comment.