From 84a153695e68835ec22d72c4b225d3601b608a48 Mon Sep 17 00:00:00 2001 From: john Date: Tue, 15 Oct 2024 17:18:10 +0200 Subject: [PATCH] use @examplesIf where necessary --- R/learner_mboost_regr_gamboost.R | 3 ++- R/learner_mgcv_classif_gam.R | 2 +- R/learner_mgcv_regr_gam.R | 3 +-- R/learner_partykit_classif_mob.R | 2 +- R/learner_partykit_regr_mob.R | 2 +- R/learner_randomForestSRC_classif_imbalanced_rfsrc.R | 2 +- R/learner_randomForestSRC_classif_rfsrc.R | 2 +- R/learner_randomForestSRC_regr_rfsrc.R | 2 +- R/learner_randomForestSRC_surv_rfsrc.R | 2 +- R/learner_randomForest_classif_randomForest.R | 2 +- R/learner_randomForest_regr_randomForest.R | 2 +- R/learner_ranger_surv_ranger.R | 2 +- man/mlr_learners_classif.gam.Rd | 2 ++ man/mlr_learners_classif.imbalanced_rfsrc.Rd | 3 ++- man/mlr_learners_classif.mob.Rd | 2 ++ man/mlr_learners_classif.randomForest.Rd | 2 ++ man/mlr_learners_classif.rfsrc.Rd | 2 ++ man/mlr_learners_regr.gam.Rd | 3 ++- man/mlr_learners_regr.gamboost.Rd | 3 ++- man/mlr_learners_regr.mob.Rd | 2 ++ man/mlr_learners_regr.randomForest.Rd | 2 ++ man/mlr_learners_regr.rfsrc.Rd | 2 ++ man/mlr_learners_surv.ranger.Rd | 2 ++ man/mlr_learners_surv.rfsrc.Rd | 2 ++ 24 files changed, 37 insertions(+), 16 deletions(-) diff --git a/R/learner_mboost_regr_gamboost.R b/R/learner_mboost_regr_gamboost.R index 2e82153ed..629dc3786 100644 --- a/R/learner_mboost_regr_gamboost.R +++ b/R/learner_mboost_regr_gamboost.R @@ -15,8 +15,9 @@ #' @export #' @template seealso_learner #' @examples +#' # Define the Learner #' learner = lrn("regr.gamboost", baselearner = "bols") -#' learner +#' print(learner) LearnerRegrGAMBoost = R6Class("LearnerRegrGAMBoost", inherit = LearnerRegr, public = list( diff --git a/R/learner_mgcv_classif_gam.R b/R/learner_mgcv_classif_gam.R index a2c0b2bb8..a2919b593 100644 --- a/R/learner_mgcv_classif_gam.R +++ b/R/learner_mgcv_classif_gam.R @@ -22,7 +22,7 @@ #' @references #' `r format_bib("hastie2017generalized", "wood2012mgcv")` #' -#' @examples +#' @examplesIf requireNamespace("mgcv", quietly = TRUE) #' # simple example #' t = mlr3::tsk("spam")$filter(1:1000) #' l = mlr3::lrn("classif.gam") diff --git a/R/learner_mgcv_regr_gam.R b/R/learner_mgcv_regr_gam.R index 182309ee4..bc6b8b9cb 100644 --- a/R/learner_mgcv_regr_gam.R +++ b/R/learner_mgcv_regr_gam.R @@ -19,8 +19,7 @@ #' @references #' `r format_bib("hastie2017generalized", "wood2012mgcv")` #' -#' @examples -#' +#' @examplesIf requireNamespace("mgcv", quietly = TRUE) #' # simple example #' t = mlr3::tsk("mtcars") #' l = mlr3::lrn("regr.gam") diff --git a/R/learner_partykit_classif_mob.R b/R/learner_partykit_classif_mob.R index 9b09e2ebe..7a52138be 100644 --- a/R/learner_partykit_classif_mob.R +++ b/R/learner_partykit_classif_mob.R @@ -14,7 +14,7 @@ #' #' @export #' @template seealso_learner -#' @examples +#' @examplesIf requireNamespace("partykit", quietly = TRUE) #' library(mlr3) #' logit_ = function(y, x, start = NULL, weights = NULL, offset = NULL, ...) { #' glm(y ~ 1, family = binomial, start = start, ...) diff --git a/R/learner_partykit_regr_mob.R b/R/learner_partykit_regr_mob.R index 7a48f482b..7d5a1c55c 100644 --- a/R/learner_partykit_regr_mob.R +++ b/R/learner_partykit_regr_mob.R @@ -14,7 +14,7 @@ #' #' @export #' @template seealso_learner -#' @examples +#' @examplesIf requireNamespace("partykit", quietly = TRUE) #' library(mlr3) #' lm_ = function(y, x, start = NULL, weights = NULL, offset = NULL, ...) { #' lm(y ~ 1, ...) diff --git a/R/learner_randomForestSRC_classif_imbalanced_rfsrc.R b/R/learner_randomForestSRC_classif_imbalanced_rfsrc.R index ba03e3730..b47b0eb06 100644 --- a/R/learner_randomForestSRC_classif_imbalanced_rfsrc.R +++ b/R/learner_randomForestSRC_classif_imbalanced_rfsrc.R @@ -16,7 +16,7 @@ #' `r format_bib("obrien2019imbrfsrc", "chen2004imbrf")` #' #' @template seealso_learner -#' @examples +#' @examplesIf requireNamespace("randomForestSRC", quietly = TRUE) #' # Define the Learner #' learner = mlr3::lrn("classif.imbalanced_rfsrc", importance = "TRUE") #' print(learner) diff --git a/R/learner_randomForestSRC_classif_rfsrc.R b/R/learner_randomForestSRC_classif_rfsrc.R index 2557e0384..e7d1463e9 100644 --- a/R/learner_randomForestSRC_classif_rfsrc.R +++ b/R/learner_randomForestSRC_classif_rfsrc.R @@ -23,7 +23,7 @@ #' `r format_bib("breiman_2001")` #' #' @template seealso_learner -#' @examples +#' @examplesIf requireNamespace("randomForestSRC", quietly = TRUE) #' # Define the Learner #' learner = mlr3::lrn("classif.rfsrc", importance = "TRUE") #' print(learner) diff --git a/R/learner_randomForestSRC_regr_rfsrc.R b/R/learner_randomForestSRC_regr_rfsrc.R index bb72f1315..381223c75 100644 --- a/R/learner_randomForestSRC_regr_rfsrc.R +++ b/R/learner_randomForestSRC_regr_rfsrc.R @@ -15,7 +15,7 @@ #' `r format_bib("breiman_2001")` #' #' @template seealso_learner -#' @examples +#' @examplesIf requireNamespace("randomForestSRC", quietly = TRUE) #' # Define the Learner #' learner = mlr3::lrn("regr.rfsrc", importance = "TRUE") #' print(learner) diff --git a/R/learner_randomForestSRC_surv_rfsrc.R b/R/learner_randomForestSRC_surv_rfsrc.R index 7fcfab28c..399cf8e28 100644 --- a/R/learner_randomForestSRC_surv_rfsrc.R +++ b/R/learner_randomForestSRC_surv_rfsrc.R @@ -35,7 +35,7 @@ #' `r format_bib("ishwaran_2008", "breiman_2001")` #' #' @template seealso_learner -#' @examples +#' @examplesIf requireNamespace("randomForestSRC", quietly = TRUE) #' # Define the Learner #' learner = mlr3::lrn("surv.rfsrc", importance = "TRUE") #' print(learner) diff --git a/R/learner_randomForest_classif_randomForest.R b/R/learner_randomForest_classif_randomForest.R index c6eedbe1f..8bb7914e7 100644 --- a/R/learner_randomForest_classif_randomForest.R +++ b/R/learner_randomForest_classif_randomForest.R @@ -13,7 +13,7 @@ #' `r format_bib("breiman_2001")` #' #' @template seealso_learner -#' @examples +#' @examplesIf requireNamespace("randomForest", quietly = TRUE) #' # Define the Learner #' learner = mlr3::lrn("classif.randomForest", importance = "accuracy") #' print(learner) diff --git a/R/learner_randomForest_regr_randomForest.R b/R/learner_randomForest_regr_randomForest.R index f81f47482..7674217be 100644 --- a/R/learner_randomForest_regr_randomForest.R +++ b/R/learner_randomForest_regr_randomForest.R @@ -13,7 +13,7 @@ #' `r format_bib("breiman_2001")` #' #' @template seealso_learner -#' @examples +#' @examplesIf requireNamespace("randomForest", quietly = TRUE) #' # Define the Learner #' learner = mlr3::lrn("regr.randomForest", importance = "mse") #' print(learner) diff --git a/R/learner_ranger_surv_ranger.R b/R/learner_ranger_surv_ranger.R index 5d1bea9de..3e0a2afbe 100644 --- a/R/learner_ranger_surv_ranger.R +++ b/R/learner_ranger_surv_ranger.R @@ -28,7 +28,7 @@ #' `r format_bib("wright_2017", "breiman_2001")` #' #' @template seealso_learner -#' @examples +#' @examplesIf requireNamespace("ranger", quietly = TRUE) #' # Define the Learner #' learner = mlr3::lrn("surv.ranger", importance = "permutation") #' print(learner) diff --git a/man/mlr_learners_classif.gam.Rd b/man/mlr_learners_classif.gam.Rd index 0bdb819ad..f9c69982b 100644 --- a/man/mlr_learners_classif.gam.Rd +++ b/man/mlr_learners_classif.gam.Rd @@ -83,6 +83,7 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \examples{ +\dontshow{if (requireNamespace("mgcv", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # simple example t = mlr3::tsk("spam")$filter(1:1000) l = mlr3::lrn("classif.gam") @@ -91,6 +92,7 @@ l$param_set$set_values( ) l$train(t) l$model +\dontshow{\}) # examplesIf} } \references{ Hastie, J T, Tibshirani, J R (2017). diff --git a/man/mlr_learners_classif.imbalanced_rfsrc.Rd b/man/mlr_learners_classif.imbalanced_rfsrc.Rd index 22b125e2a..b0595a89f 100644 --- a/man/mlr_learners_classif.imbalanced_rfsrc.Rd +++ b/man/mlr_learners_classif.imbalanced_rfsrc.Rd @@ -88,6 +88,7 @@ set to 1 by default. } \examples{ +\dontshow{if (requireNamespace("randomForestSRC", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Define the Learner learner = mlr3::lrn("classif.imbalanced_rfsrc", importance = "TRUE") print(learner) @@ -108,7 +109,7 @@ predictions = learner$predict(task, row_ids = ids$test) # Score the predictions predictions$score() - +\dontshow{\}) # examplesIf} } \references{ O’Brien R, Ishwaran H (2019). diff --git a/man/mlr_learners_classif.mob.Rd b/man/mlr_learners_classif.mob.Rd index a3becf584..865eead8a 100644 --- a/man/mlr_learners_classif.mob.Rd +++ b/man/mlr_learners_classif.mob.Rd @@ -66,6 +66,7 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \examples{ +\dontshow{if (requireNamespace("partykit", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(mlr3) logit_ = function(y, x, start = NULL, weights = NULL, offset = NULL, ...) { glm(y ~ 1, family = binomial, start = start, ...) @@ -92,6 +93,7 @@ learner$param_set$values$predict_fun = predict_fun ids = partition(task) learner$train(task, row_ids = ids$train) learner$predict(task, row_ids = ids$test) +\dontshow{\}) # examplesIf} } \references{ Hothorn T, Zeileis A (2015). diff --git a/man/mlr_learners_classif.randomForest.Rd b/man/mlr_learners_classif.randomForest.Rd index 42ffebd12..e87117ab2 100644 --- a/man/mlr_learners_classif.randomForest.Rd +++ b/man/mlr_learners_classif.randomForest.Rd @@ -52,6 +52,7 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \examples{ +\dontshow{if (requireNamespace("randomForest", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Define the Learner learner = mlr3::lrn("classif.randomForest", importance = "accuracy") print(learner) @@ -72,6 +73,7 @@ predictions = learner$predict(task, row_ids = ids$test) # Score the predictions predictions$score() +\dontshow{\}) # examplesIf} } \references{ Breiman, Leo (2001). diff --git a/man/mlr_learners_classif.rfsrc.Rd b/man/mlr_learners_classif.rfsrc.Rd index dfc9ae528..cbaf467c2 100644 --- a/man/mlr_learners_classif.rfsrc.Rd +++ b/man/mlr_learners_classif.rfsrc.Rd @@ -84,6 +84,7 @@ set to 1 by default. } \examples{ +\dontshow{if (requireNamespace("randomForestSRC", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Define the Learner learner = mlr3::lrn("classif.rfsrc", importance = "TRUE") print(learner) @@ -104,6 +105,7 @@ predictions = learner$predict(task, row_ids = ids$test) # Score the predictions predictions$score() +\dontshow{\}) # examplesIf} } \references{ Breiman, Leo (2001). diff --git a/man/mlr_learners_regr.gam.Rd b/man/mlr_learners_regr.gam.Rd index 8b2b8b8ca..33b20c8d7 100644 --- a/man/mlr_learners_regr.gam.Rd +++ b/man/mlr_learners_regr.gam.Rd @@ -80,13 +80,14 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \examples{ - +\dontshow{if (requireNamespace("mgcv", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # simple example t = mlr3::tsk("mtcars") l = mlr3::lrn("regr.gam") l$param_set$values$formula = mpg ~ cyl + am + s(disp) + s(hp) l$train(t) l$model +\dontshow{\}) # examplesIf} } \references{ Hastie, J T, Tibshirani, J R (2017). diff --git a/man/mlr_learners_regr.gamboost.Rd b/man/mlr_learners_regr.gamboost.Rd index 3770b3f44..835a23c0a 100644 --- a/man/mlr_learners_regr.gamboost.Rd +++ b/man/mlr_learners_regr.gamboost.Rd @@ -47,8 +47,9 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \examples{ +# Define the Learner learner = lrn("regr.gamboost", baselearner = "bols") -learner +print(learner) } \references{ Bühlmann, Peter, Yu, Bin (2003). diff --git a/man/mlr_learners_regr.mob.Rd b/man/mlr_learners_regr.mob.Rd index 77cce3e56..8b23ab85f 100644 --- a/man/mlr_learners_regr.mob.Rd +++ b/man/mlr_learners_regr.mob.Rd @@ -66,6 +66,7 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \examples{ +\dontshow{if (requireNamespace("partykit", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} library(mlr3) lm_ = function(y, x, start = NULL, weights = NULL, offset = NULL, ...) { lm(y ~ 1, ...) @@ -84,6 +85,7 @@ task = tsk("mtcars") ids = partition(task) learner$train(task, row_ids = ids$train) learner$predict(task, row_ids = ids$test) +\dontshow{\}) # examplesIf} } \references{ Hothorn T, Zeileis A (2015). diff --git a/man/mlr_learners_regr.randomForest.Rd b/man/mlr_learners_regr.randomForest.Rd index 605350831..95bcd7faa 100644 --- a/man/mlr_learners_regr.randomForest.Rd +++ b/man/mlr_learners_regr.randomForest.Rd @@ -50,6 +50,7 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \examples{ +\dontshow{if (requireNamespace("randomForest", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Define the Learner learner = mlr3::lrn("regr.randomForest", importance = "mse") print(learner) @@ -70,6 +71,7 @@ predictions = learner$predict(task, row_ids = ids$test) # Score the predictions predictions$score() +\dontshow{\}) # examplesIf} } \references{ Breiman, Leo (2001). diff --git a/man/mlr_learners_regr.rfsrc.Rd b/man/mlr_learners_regr.rfsrc.Rd index 30223a75b..d311598c2 100644 --- a/man/mlr_learners_regr.rfsrc.Rd +++ b/man/mlr_learners_regr.rfsrc.Rd @@ -84,6 +84,7 @@ set to 1 by default. } \examples{ +\dontshow{if (requireNamespace("randomForestSRC", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Define the Learner learner = mlr3::lrn("regr.rfsrc", importance = "TRUE") print(learner) @@ -104,6 +105,7 @@ predictions = learner$predict(task, row_ids = ids$test) # Score the predictions predictions$score() +\dontshow{\}) # examplesIf} } \references{ Breiman, Leo (2001). diff --git a/man/mlr_learners_surv.ranger.Rd b/man/mlr_learners_surv.ranger.Rd index d6c7a8dba..227e975b3 100644 --- a/man/mlr_learners_surv.ranger.Rd +++ b/man/mlr_learners_surv.ranger.Rd @@ -89,6 +89,7 @@ This \link[mlr3:Learner]{Learner} can be instantiated via \link[mlr3:mlr_sugar]{ } \examples{ +\dontshow{if (requireNamespace("ranger", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Define the Learner learner = mlr3::lrn("surv.ranger", importance = "permutation") print(learner) @@ -110,6 +111,7 @@ predictions = learner$predict(task, row_ids = ids$test) # Score the predictions predictions$score() +\dontshow{\}) # examplesIf} } \references{ Wright, N. M, Ziegler, Andreas (2017). diff --git a/man/mlr_learners_surv.rfsrc.Rd b/man/mlr_learners_surv.rfsrc.Rd index c910a3503..c7b579a79 100644 --- a/man/mlr_learners_surv.rfsrc.Rd +++ b/man/mlr_learners_surv.rfsrc.Rd @@ -111,6 +111,7 @@ set to 1 by default. } \examples{ +\dontshow{if (requireNamespace("randomForestSRC", quietly = TRUE)) (if (getRversion() >= "3.4") withAutoprint else force)(\{ # examplesIf} # Define the Learner learner = mlr3::lrn("surv.rfsrc", importance = "TRUE") print(learner) @@ -132,6 +133,7 @@ predictions = learner$predict(task, row_ids = ids$test) # Score the predictions predictions$score() +\dontshow{\}) # examplesIf} } \references{ Ishwaran H, Kogalur UB, Blackstone EH, Lauer MS (2008).