diff --git a/.Rbuildignore b/.Rbuildignore index aa0489d0..70a566d2 100644 --- a/.Rbuildignore +++ b/.Rbuildignore @@ -18,3 +18,4 @@ ^revdep$ ^cran-comments\.md$ ^CRAN-SUBMISSION$ +^.claude$ diff --git a/.github/workflows/no-suggest-cmd-check.yml b/.github/workflows/no-suggest-cmd-check.yml index 7a62e61d..4761fc72 100644 --- a/.github/workflows/no-suggest-cmd-check.yml +++ b/.github/workflows/no-suggest-cmd-check.yml @@ -1,4 +1,4 @@ -# r cmd check workflow without suggests of the mlr3 ecosystem v0.2.0 +# r cmd check workflow without suggests of the mlr3 ecosystem v0.3.1 # https://github.com/mlr-org/actions on: workflow_dispatch: @@ -33,7 +33,7 @@ jobs: - {os: ubuntu-latest, r: 'release'} steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v5 - uses: r-lib/actions/setup-pandoc@v2 @@ -43,9 +43,14 @@ jobs: - uses: r-lib/actions/setup-r-dependencies@v2 with: - extra-packages: any::rcmdcheck + extra-packages: | + any::rcmdcheck + any::testthat + any::knitr + any::rmarkdown needs: check dependencies: '"hard"' + cache: false - uses: mxschmitt/action-tmate@v3 if: ${{ github.event_name == 'workflow_dispatch' && inputs.debug_enabled }} @@ -54,5 +59,4 @@ jobs: - uses: r-lib/actions/check-r-package@v2 with: - error-on: '"note"' args: 'c("--no-manual", "--as-cran")' diff --git a/DESCRIPTION b/DESCRIPTION index 9601ab12..c0e65d59 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -26,7 +26,8 @@ License: LGPL-3 URL: https://mlr3viz.mlr-org.com, https://github.com/mlr-org/mlr3viz BugReports: https://github.com/mlr-org/mlr3viz/issues Depends: - R (>= 3.3.0) + R (>= 3.3.0), + mlr3 (>= 1.3.0) Imports: checkmate, data.table, @@ -37,6 +38,7 @@ Imports: viridis Suggests: bbotk (>= 1.0.0), + clue, cluster, GGally, ggdendro, @@ -45,7 +47,6 @@ Suggests: glmnet, knitr, lgr, - mlr3 (>= 0.6.0), mlr3cluster, mlr3filters, mlr3fselect (>= 1.3.0), diff --git a/NAMESPACE b/NAMESPACE index 376d2250..476c31b3 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -54,6 +54,7 @@ export(plot_learner_prediction) import(checkmate) import(data.table) import(ggplot2) +import(mlr3) import(mlr3misc) importFrom(ggplot2,autoplot) importFrom(ggplot2,fortify) diff --git a/R/BenchmarkResult.R b/R/BenchmarkResult.R index 5ee06be0..2f1ff46a 100644 --- a/R/BenchmarkResult.R +++ b/R/BenchmarkResult.R @@ -28,19 +28,15 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces("precrec", quietly = TRUE)) { +#' tasks = tsks(c("pima", "sonar")) +#' learner = lrns(c("classif.featureless", "classif.rpart"), predict_type = "prob") +#' resampling = rsmps("cv") +#' object = benchmark(benchmark_grid(tasks, learner, resampling)) #' -#' tasks = tsks(c("pima", "sonar")) -#' learner = lrns(c("classif.featureless", "classif.rpart"), -#' predict_type = "prob") -#' resampling = rsmps("cv") -#' object = benchmark(benchmark_grid(tasks, learner, resampling)) -#' -#' head(fortify(object)) -#' autoplot(object) -#' autoplot(object$clone(deep = TRUE)$filter(task_ids = "pima"), type = "roc") +#' head(fortify(object)) +#' autoplot(object) +#' autoplot(object$clone(deep = TRUE)$filter(task_ids = "pima"), type = "roc") #' } autoplot.BenchmarkResult = function(object, type = "boxplot", measure = NULL, theme = theme_minimal(), ...) { assert_choice(type, choices = c("boxplot", "roc", "prc", "ci"), null.ok = FALSE) diff --git a/R/EnsembleFSResult.R b/R/EnsembleFSResult.R index 905258f1..8d32045f 100644 --- a/R/EnsembleFSResult.R +++ b/R/EnsembleFSResult.R @@ -35,12 +35,11 @@ #' #' @return [ggplot2::ggplot()]. #' @examples +#' if (mlr3misc::require_namespaces("mlr3fselect", quietly = TRUE)) { #' \donttest{ -#' if (requireNamespace("mlr3")) { -#' library(mlr3) +#' set.seed (42) #' library(mlr3fselect) #' -#' set.seed (42) #' efsr = ensemble_fselect( #' fselector = fs("random_search"), #' task = tsk("sonar"), diff --git a/R/Filter.R b/R/Filter.R index 83146dfd..7f6927c9 100644 --- a/R/Filter.R +++ b/R/Filter.R @@ -18,17 +18,15 @@ #' @return [ggplot2::ggplot()]. #' @export #' @examples -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) -#' library(mlr3filters) +#' if (mlr3misc::require_namespaces("mlr3filters", quietly = TRUE)) { +#' library(mlr3filters) #' -#' task = tsk("mtcars") -#' f = flt("correlation") -#' f$calculate(task) +#' task = tsk("mtcars") +#' f = flt("correlation") +#' f$calculate(task) #' -#' head(fortify(f)) -#' autoplot(f, n = 5) +#' head(fortify(f)) +#' autoplot(f, n = 5) #' } autoplot.Filter = function(object, type = "boxplot", n = Inf, theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("boxplot"), null.ok = FALSE) diff --git a/R/LearnerClassif.R b/R/LearnerClassif.R index 797427a4..16534fae 100644 --- a/R/LearnerClassif.R +++ b/R/LearnerClassif.R @@ -21,17 +21,12 @@ #' @export #' @examples #' \donttest{ -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) -#' #' task = tsk("pima")$select(c("age", "pedigree")) #' learner = lrn("classif.rpart", predict_type = "prob") #' learner$train(task) #' #' autoplot(learner, type = "prediction", task) #' } -#' } autoplot.LearnerClassif = function(object, type = "prediction", task, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("prediction"), null.ok = FALSE) diff --git a/R/LearnerClassifGlmnet.R b/R/LearnerClassifGlmnet.R index 82af84f7..6d870c6f 100644 --- a/R/LearnerClassifGlmnet.R +++ b/R/LearnerClassifGlmnet.R @@ -24,9 +24,8 @@ #' #' @export #' @examples +#' if (mlr3misc::require_namespaces("mlr3learners", quietly = TRUE)) { #' \dontrun{ -#' library(mlr3) -#' library(mlr3viz) #' library(mlr3learners) #' #' # classification @@ -41,6 +40,7 @@ #' learner$train(task) #' autoplot(learner, type = "ggfortify") #' } +#' } autoplot.LearnerClassifGlmnet = function(object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("prediction", "ggfortify"), null.ok = FALSE) assert_has_model(object) diff --git a/R/LearnerClassifRpart.R b/R/LearnerClassifRpart.R index f2b588c9..523a0cd0 100644 --- a/R/LearnerClassifRpart.R +++ b/R/LearnerClassifRpart.R @@ -21,21 +21,18 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces(c("partykit", "ggparty"), quietly = TRUE)) { +#' # classification +#' task = tsk("iris") +#' learner = lrn("classif.rpart", keep_model = TRUE) +#' learner$train(task) +#' autoplot(learner, type = "ggparty") #' -#' # classification -#' task = tsk("iris") -#' learner = lrn("classif.rpart", keep_model = TRUE) -#' learner$train(task) -#' autoplot(learner, type = "ggparty") -#' -#' # regression -#' task = tsk("mtcars") -#' learner = lrn("regr.rpart", keep_model = TRUE) -#' learner$train(task) -#' autoplot(learner, type = "ggparty") +#' # regression +#' task = tsk("mtcars") +#' learner = lrn("regr.rpart", keep_model = TRUE) +#' learner$train(task) +#' autoplot(learner, type = "ggparty") #' } autoplot.LearnerClassifRpart = function(object, type = "prediction", task = NULL, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("prediction", "ggparty"), null.ok = FALSE) diff --git a/R/LearnerClustHierarchical.R b/R/LearnerClustHierarchical.R index 1b77516e..5ba9bcb6 100644 --- a/R/LearnerClustHierarchical.R +++ b/R/LearnerClustHierarchical.R @@ -23,27 +23,25 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3cluster) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces("mlr3cluster", quietly = TRUE)) { +#' library(mlr3cluster) #' -#' task = tsk("usarrests") +#' task = tsk("usarrests") #' -#' # agnes clustering -#' learner = lrn("clust.agnes") -#' learner$train(task) -#' autoplot(learner) +#' # agnes clustering +#' learner = lrn("clust.agnes") +#' learner$train(task) +#' autoplot(learner) #' -#' # diana clustering -#' learner = lrn("clust.diana") -#' learner$train(task) -#' autoplot(learner) +#' # diana clustering +#' learner = lrn("clust.diana") +#' learner$train(task) +#' autoplot(learner) #' -#' # hclust clustering -#' learner = lrn("clust.hclust") -#' learner$train(task) -#' autoplot(learner, type = "scree") +#' # hclust clustering +#' learner = lrn("clust.hclust") +#' learner$train(task) +#' autoplot(learner, type = "scree") #' } autoplot.LearnerClustHierarchical = function(object, type = "dend", task = NULL, theme = theme_minimal(), theme_dendro = TRUE, ...) { # nolint assert_choice(type, choices = c("dend", "scree"), null.ok = FALSE) diff --git a/R/LearnerRegr.R b/R/LearnerRegr.R index 32b51869..9ba8b94d 100644 --- a/R/LearnerRegr.R +++ b/R/LearnerRegr.R @@ -21,17 +21,12 @@ #' @export #' @examples #' \donttest{ -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) -#' #' task = tsk("mtcars")$select(c("am", "carb")) #' learner = lrn("regr.rpart") #' learner$train(task) #' #' autoplot(learner, type = "prediction", task) #' } -#' } autoplot.LearnerRegr = function(object, type = "prediction", task, grid_points = 100L, expand_range = 0, theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("prediction"), null.ok = FALSE) diff --git a/R/OptimInstanceBatchSingleCrit.R b/R/OptimInstanceBatchSingleCrit.R index 3f3e57e6..bde32267 100644 --- a/R/OptimInstanceBatchSingleCrit.R +++ b/R/OptimInstanceBatchSingleCrit.R @@ -44,45 +44,44 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3") && requireNamespace("bbotk") && requireNamespace("patchwork")) { -#' library(bbotk) -#' library(paradox) +#' if (mlr3misc::require_namespaces(c("paradox", "bbotk", "patchwork"), quietly = TRUE)) { +#' library(bbotk) #' -#' fun = function(xs) { -#' c(y = -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10) -#' } -#' domain = ps( -#' x1 = p_dbl(-10, 10), -#' x2 = p_dbl(-5, 5) -#' ) -#' codomain = ps( -#' y = p_dbl(tags = "maximize") -#' ) -#' obfun = ObjectiveRFun$new( -#' fun = fun, -#' domain = domain, -#' codomain = codomain -#' ) +#' fun = function(xs) { +#' c(y = -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10) +#' } +#' domain = ps( +#' x1 = p_dbl(-10, 10), +#' x2 = p_dbl(-5, 5) +#' ) +#' codomain = ps( +#' y = p_dbl(tags = "maximize") +#' ) +#' obfun = ObjectiveRFun$new( +#' fun = fun, +#' domain = domain, +#' codomain = codomain +#' ) #' -#' instance = oi(objective = obfun, terminator = trm("evals", n_evals = 20)) +#' instance = oi(objective = obfun, terminator = trm("evals", n_evals = 20)) #' -#' optimizer = opt("random_search", batch_size = 2) -#' optimizer$optimize(instance) +#' optimizer = opt("random_search", batch_size = 2) +#' optimizer$optimize(instance) #' -#' # plot y versus batch number -#' print(autoplot(instance, type = "performance")) +#' # plot y versus batch number +#' print(autoplot(instance, type = "performance")) #' -#' # plot x1 values versus performance -#' print(autoplot(instance, type = "marginal", cols_x = "x1")) +#' # plot x1 values versus performance +#' print(autoplot(instance, type = "marginal", cols_x = "x1")) #' -#' # plot parallel coordinates plot -#' print(autoplot(instance, type = "parallel")) +#' # plot parallel coordinates plot +#' print(autoplot(instance, type = "parallel")) #' -#' # plot pairs -#' print(autoplot(instance, type = "pairs")) +#' # plot pairs +#' print(autoplot(instance, type = "pairs")) #' -#' # plot incumbent -#' print(autoplot(instance, type = "incumbent")) +#' # plot incumbent +#' print(autoplot(instance, type = "incumbent")) #' } autoplot.OptimInstanceBatchSingleCrit = function(object, type = "marginal", cols_x = NULL, trafo = FALSE, learner = mlr3::lrn("regr.ranger"), grid_resolution = 100, batch = NULL, theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("marginal", "performance", "parameter", "parallel", diff --git a/R/PredictionClassif.R b/R/PredictionClassif.R index 0b271440..36389de4 100644 --- a/R/PredictionClassif.R +++ b/R/PredictionClassif.R @@ -26,18 +26,15 @@ #' @export #' @examples #' \donttest{ -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces("precrec", quietly = TRUE)) { +#' task = tsk("spam") +#' learner = lrn("classif.rpart", predict_type = "prob") +#' object = learner$train(task)$predict(task) #' -#' task = tsk("spam") -#' learner = lrn("classif.rpart", predict_type = "prob") -#' object = learner$train(task)$predict(task) -#' -#' head(fortify(object)) -#' autoplot(object) -#' autoplot(object, type = "roc") -#' autoplot(object, type = "prc") +#' head(fortify(object)) +#' autoplot(object) +#' autoplot(object, type = "roc") +#' autoplot(object, type = "prc") #' } #' } autoplot.PredictionClassif = function(object, type = "stacked", measure = NULL, theme = theme_minimal(), ...) { # nolint diff --git a/R/PredictionClust.R b/R/PredictionClust.R index 6ebb76b1..b8580df2 100644 --- a/R/PredictionClust.R +++ b/R/PredictionClust.R @@ -26,17 +26,15 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3cluster) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces(c("clue", "mlr3cluster"), quietly = TRUE)) { +#' library(mlr3cluster) #' -#' task = tsk("usarrests") -#' learner = lrn("clust.kmeans", centers = 3) -#' object = learner$train(task)$predict(task) +#' task = tsk("usarrests") +#' learner = lrn("clust.kmeans", centers = 3) +#' object = learner$train(task)$predict(task) #' -#' head(fortify(object)) -#' autoplot(object, task) +#' head(fortify(object)) +#' autoplot(object, task) #' } autoplot.PredictionClust = function(object, task, row_ids = NULL, type = "scatter", theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("scatter", "sil", "pca"), null.ok = FALSE) diff --git a/R/PredictionRegr.R b/R/PredictionRegr.R index 072ea24e..ea99df66 100644 --- a/R/PredictionRegr.R +++ b/R/PredictionRegr.R @@ -29,25 +29,21 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces("mlr3learners", quietly = TRUE)) { +#' library(mlr3learners) #' -#' task = tsk("mtcars") -#' learner = lrn("regr.rpart") -#' object = learner$train(task)$predict(task) +#' task = tsk("mtcars") +#' learner = lrn("regr.rpart") +#' object = learner$train(task)$predict(task) #' -#' head(fortify(object)) -#' autoplot(object) -#' autoplot(object, type = "histogram", binwidth = 1) -#' autoplot(object, type = "residual") +#' head(fortify(object)) +#' autoplot(object) +#' autoplot(object, type = "histogram", binwidth = 1) +#' autoplot(object, type = "residual") #' -#' if (requireNamespace("mlr3learners")) { -#' library(mlr3learners) -#' learner = lrn("regr.ranger", predict_type = "se") -#' object = learner$train(task)$predict(task) -#' autoplot(object, type = "confidence") -#' } +#' learner = lrn("regr.ranger", predict_type = "se") +#' object = learner$train(task)$predict(task) +#' autoplot(object, type = "confidence") #' } autoplot.PredictionRegr = function(object, type = "xy", binwidth = NULL, theme = theme_minimal(), quantile = 1.96, ...) { assert_choice(type, choices = c("xy", "histogram", "residual", "confidence"), null.ok = FALSE) diff --git a/R/ResampleResult.R b/R/ResampleResult.R index 5dfb51b2..47614e93 100644 --- a/R/ResampleResult.R +++ b/R/ResampleResult.R @@ -40,37 +40,34 @@ #' @export #' @examples #' \donttest{ -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces("precrec", quietly = TRUE)) { +#' task = tsk("sonar") +#' learner = lrn("classif.rpart", predict_type = "prob") +#' resampling = rsmp("cv", folds = 3) +#' object = resample(task, learner, resampling) #' -#' task = tsk("sonar") -#' learner = lrn("classif.rpart", predict_type = "prob") -#' resampling = rsmp("cv", folds = 3) -#' object = resample(task, learner, resampling) +#' head(fortify(object)) #' -#' head(fortify(object)) +#' # Default: boxplot +#' autoplot(object) #' -#' # Default: boxplot -#' autoplot(object) +#' # Histogram +#' autoplot(object, type = "histogram", bins = 30) #' -#' # Histogram -#' autoplot(object, type = "histogram", bins = 30) +#' # ROC curve, averaged over resampling folds: +#' autoplot(object, type = "roc") #' -#' # ROC curve, averaged over resampling folds: -#' autoplot(object, type = "roc") +#' # ROC curve of joint prediction object: +#' autoplot(object$prediction(), type = "roc") #' -#' # ROC curve of joint prediction object: -#' autoplot(object$prediction(), type = "roc") +#' # Precision Recall Curve +#' autoplot(object, type = "prc") #' -#' # Precision Recall Curve -#' autoplot(object, type = "prc") -#' -#' # Prediction Plot -#' task = tsk("iris")$select(c("Sepal.Length", "Sepal.Width")) -#' resampling = rsmp("cv", folds = 3) -#' object = resample(task, learner, resampling, store_models = TRUE) -#' autoplot(object, type = "prediction") +#' # Prediction Plot +#' task = tsk("iris")$select(c("Sepal.Length", "Sepal.Width")) +#' resampling = rsmp("cv", folds = 3) +#' object = resample(task, learner, resampling, store_models = TRUE) +#' autoplot(object, type = "prediction") #' } #' } autoplot.ResampleResult = function(object, type = "boxplot", measure = NULL, predict_sets = "test", binwidth = NULL, theme = theme_minimal(), ...) { diff --git a/R/TaskClassif.R b/R/TaskClassif.R index b13e55ac..e4703eb4 100644 --- a/R/TaskClassif.R +++ b/R/TaskClassif.R @@ -20,17 +20,13 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces("GGally", quietly = TRUE)) { +#' task = tsk("iris") #' -#' task = tsk("iris") -#' -#' head(fortify(task)) -#' autoplot(task) -#' autoplot(task$clone()$select(c("Sepal.Length", "Sepal.Width")), -#' type = "pairs") -#' autoplot(task, type = "duo") +#' head(fortify(task)) +#' autoplot(task) +#' autoplot(task$clone()$select(c("Sepal.Length", "Sepal.Width")), type = "pairs") +#' autoplot(task, type = "duo") #' } autoplot.TaskClassif = function(object, type = "target", theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("target", "duo", "pairs"), null.ok = FALSE) diff --git a/R/TaskClust.R b/R/TaskClust.R index f289a6cf..174798d5 100644 --- a/R/TaskClust.R +++ b/R/TaskClust.R @@ -16,15 +16,12 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3cluster) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces("mlr3cluster", quietly = TRUE)) { +#' library(mlr3cluster) +#' task = tsk("usarrests") #' -#' task = mlr_tasks$get("usarrests") -#' -#' head(fortify(task)) -#' autoplot(task) +#' head(fortify(task)) +#' autoplot(task) #' } autoplot.TaskClust = function(object, type = "pairs", theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("pairs"), null.ok = FALSE) diff --git a/R/TaskRegr.R b/R/TaskRegr.R index 60597b9a..82efefde 100644 --- a/R/TaskRegr.R +++ b/R/TaskRegr.R @@ -18,16 +18,13 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3")) { -#' library(mlr3) -#' library(mlr3viz) +#' if (mlr3misc::require_namespaces("GGally", quietly = TRUE)) { +#' task = tsk("mtcars") +#' task$select(c("am", "carb")) #' -#' task = tsk("mtcars") -#' task$select(c("am", "carb")) -#' -#' head(fortify(task)) -#' autoplot(task) -#' autoplot(task, type = "pairs") +#' head(fortify(task)) +#' autoplot(task) +#' autoplot(task, type = "pairs") #' } autoplot.TaskRegr = function(object, type = "target", theme = theme_minimal(), ...) { # nolint assert_choice(type, choices = c("target", "pairs"), null.ok = FALSE) diff --git a/R/TuningInstanceBatchSingleCrit.R b/R/TuningInstanceBatchSingleCrit.R index 0d0de20d..6070c00a 100644 --- a/R/TuningInstanceBatchSingleCrit.R +++ b/R/TuningInstanceBatchSingleCrit.R @@ -39,38 +39,38 @@ #' #' @export #' @examples -#' if (requireNamespace("mlr3tuning") && requireNamespace("patchwork")) { -#' library(mlr3tuning) +#' if (mlr3misc::require_namespaces(c("mlr3tuning", "patchwork", "paradox"), quietly = TRUE)) { +#' library(mlr3tuning) #' -#' learner = lrn("classif.rpart") -#' learner$param_set$values$cp = to_tune(0.001, 0.1) -#' learner$param_set$values$minsplit = to_tune(1, 10) +#' learner = lrn("classif.rpart") +#' learner$param_set$values$cp = to_tune(0.001, 0.1) +#' learner$param_set$values$minsplit = to_tune(1, 10) #' -#' instance = ti( -#' task = tsk("iris"), -#' learner = learner, -#' resampling = rsmp("holdout"), -#' measure = msr("classif.ce"), -#' terminator = trm("evals", n_evals = 10)) +#' instance = ti( +#' task = tsk("iris"), +#' learner = learner, +#' resampling = rsmp("holdout"), +#' measure = msr("classif.ce"), +#' terminator = trm("evals", n_evals = 10)) #' -#' tuner = tnr("random_search") +#' tuner = tnr("random_search") #' -#' tuner$optimize(instance) +#' tuner$optimize(instance) #' -#' # plot performance versus batch number -#' autoplot(instance, type = "performance") +#' # plot performance versus batch number +#' autoplot(instance, type = "performance") #' -#' # plot cp values versus performance -#' autoplot(instance, type = "marginal", cols_x = "cp") +#' # plot cp values versus performance +#' autoplot(instance, type = "marginal", cols_x = "cp") #' -#' # plot transformed parameter values versus batch number -#' autoplot(instance, type = "parameter", trafo = TRUE) +#' # plot transformed parameter values versus batch number +#' autoplot(instance, type = "parameter", trafo = TRUE) #' -#' # plot parallel coordinates plot -#' autoplot(instance, type = "parallel") +#' # plot parallel coordinates plot +#' autoplot(instance, type = "parallel") #' -#' # plot pairs -#' autoplot(instance, type = "pairs") +#' # plot pairs +#' autoplot(instance, type = "pairs") #' } autoplot.TuningInstanceBatchSingleCrit = function(object, type = "marginal", cols_x = NULL, trafo = FALSE, learner = mlr3::lrn("regr.ranger"), grid_resolution = 100, theme = theme_minimal(), ...) { autoplot.OptimInstanceBatchSingleCrit(object = object, type = type, cols_x = cols_x, trafo = trafo, learner = learner, grid_resolution = grid_resolution, theme = theme, ...) diff --git a/R/zzz.R b/R/zzz.R index a3f1a54a..e3b078bb 100644 --- a/R/zzz.R +++ b/R/zzz.R @@ -2,6 +2,7 @@ #' @import checkmate #' @import data.table #' @import ggplot2 +#' @import mlr3 #' @importFrom utils head #' @importFrom graphics plot #' @importFrom stats sd as.dendrogram diff --git a/man/autoplot.BenchmarkResult.Rd b/man/autoplot.BenchmarkResult.Rd index db2f9b34..811fecf3 100644 --- a/man/autoplot.BenchmarkResult.Rd +++ b/man/autoplot.BenchmarkResult.Rd @@ -46,19 +46,15 @@ See \code{"roc"}. } } \examples{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3viz) +if (mlr3misc::require_namespaces("precrec", quietly = TRUE)) { +tasks = tsks(c("pima", "sonar")) +learner = lrns(c("classif.featureless", "classif.rpart"), predict_type = "prob") +resampling = rsmps("cv") +object = benchmark(benchmark_grid(tasks, learner, resampling)) - tasks = tsks(c("pima", "sonar")) - learner = lrns(c("classif.featureless", "classif.rpart"), - predict_type = "prob") - resampling = rsmps("cv") - object = benchmark(benchmark_grid(tasks, learner, resampling)) - - head(fortify(object)) - autoplot(object) - autoplot(object$clone(deep = TRUE)$filter(task_ids = "pima"), type = "roc") +head(fortify(object)) +autoplot(object) +autoplot(object$clone(deep = TRUE)$filter(task_ids = "pima"), type = "roc") } } \references{ diff --git a/man/autoplot.EnsembleFSResult.Rd b/man/autoplot.EnsembleFSResult.Rd index ff710fa4..14efe40f 100644 --- a/man/autoplot.EnsembleFSResult.Rd +++ b/man/autoplot.EnsembleFSResult.Rd @@ -61,12 +61,11 @@ sets from each learner across the different resamplings. } } \examples{ +if (mlr3misc::require_namespaces("mlr3fselect", quietly = TRUE)) { \donttest{ -if (requireNamespace("mlr3")) { - library(mlr3) + set.seed (42) library(mlr3fselect) - set.seed (42) efsr = ensemble_fselect( fselector = fs("random_search"), task = tsk("sonar"), diff --git a/man/autoplot.Filter.Rd b/man/autoplot.Filter.Rd index d5487d0e..38aee598 100644 --- a/man/autoplot.Filter.Rd +++ b/man/autoplot.Filter.Rd @@ -33,16 +33,14 @@ Possible choices are: } } \examples{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3viz) - library(mlr3filters) +if (mlr3misc::require_namespaces("mlr3filters", quietly = TRUE)) { +library(mlr3filters) - task = tsk("mtcars") - f = flt("correlation") - f$calculate(task) +task = tsk("mtcars") +f = flt("correlation") +f$calculate(task) - head(fortify(f)) - autoplot(f, n = 5) +head(fortify(f)) +autoplot(f, n = 5) } } diff --git a/man/autoplot.LearnerClassif.Rd b/man/autoplot.LearnerClassif.Rd index 451f1d3e..e03baac4 100644 --- a/man/autoplot.LearnerClassif.Rd +++ b/man/autoplot.LearnerClassif.Rd @@ -47,10 +47,6 @@ Possible choices are: } \examples{ \donttest{ -if (requireNamespace("mlr3")) { -library(mlr3) -library(mlr3viz) - task = tsk("pima")$select(c("age", "pedigree")) learner = lrn("classif.rpart", predict_type = "prob") learner$train(task) @@ -58,4 +54,3 @@ learner$train(task) autoplot(learner, type = "prediction", task) } } -} diff --git a/man/autoplot.LearnerClassifGlmnet.Rd b/man/autoplot.LearnerClassifGlmnet.Rd index 1d4e53a3..27e2260d 100644 --- a/man/autoplot.LearnerClassifGlmnet.Rd +++ b/man/autoplot.LearnerClassifGlmnet.Rd @@ -81,9 +81,8 @@ Possible choices are: } } \examples{ +if (mlr3misc::require_namespaces("mlr3learners", quietly = TRUE)) { \dontrun{ -library(mlr3) -library(mlr3viz) library(mlr3learners) # classification @@ -99,6 +98,7 @@ learner$train(task) autoplot(learner, type = "ggfortify") } } +} \references{ Tang Y, Horikoshi M, Li W (2016). \dQuote{ggfortify: Unified Interface to Visualize Statistical Result of Popular R Packages.} diff --git a/man/autoplot.LearnerClassifRpart.Rd b/man/autoplot.LearnerClassifRpart.Rd index db145f51..85293a33 100644 --- a/man/autoplot.LearnerClassifRpart.Rd +++ b/man/autoplot.LearnerClassifRpart.Rd @@ -58,20 +58,17 @@ Possible choices are: } } \examples{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3viz) +if (mlr3misc::require_namespaces(c("partykit", "ggparty"), quietly = TRUE)) { +# classification +task = tsk("iris") +learner = lrn("classif.rpart", keep_model = TRUE) +learner$train(task) +autoplot(learner, type = "ggparty") - # classification - task = tsk("iris") - learner = lrn("classif.rpart", keep_model = TRUE) - learner$train(task) - autoplot(learner, type = "ggparty") - - # regression - task = tsk("mtcars") - learner = lrn("regr.rpart", keep_model = TRUE) - learner$train(task) - autoplot(learner, type = "ggparty") +# regression +task = tsk("mtcars") +learner = lrn("regr.rpart", keep_model = TRUE) +learner$train(task) +autoplot(learner, type = "ggparty") } } diff --git a/man/autoplot.LearnerClustHierarchical.Rd b/man/autoplot.LearnerClustHierarchical.Rd index 0e6b885b..cc647cc2 100644 --- a/man/autoplot.LearnerClustHierarchical.Rd +++ b/man/autoplot.LearnerClustHierarchical.Rd @@ -45,26 +45,24 @@ Possible choices are: } } \examples{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3cluster) - library(mlr3viz) +if (mlr3misc::require_namespaces("mlr3cluster", quietly = TRUE)) { +library(mlr3cluster) - task = tsk("usarrests") +task = tsk("usarrests") - # agnes clustering - learner = lrn("clust.agnes") - learner$train(task) - autoplot(learner) +# agnes clustering +learner = lrn("clust.agnes") +learner$train(task) +autoplot(learner) - # diana clustering - learner = lrn("clust.diana") - learner$train(task) - autoplot(learner) +# diana clustering +learner = lrn("clust.diana") +learner$train(task) +autoplot(learner) - # hclust clustering - learner = lrn("clust.hclust") - learner$train(task) - autoplot(learner, type = "scree") +# hclust clustering +learner = lrn("clust.hclust") +learner$train(task) +autoplot(learner, type = "scree") } } diff --git a/man/autoplot.LearnerRegr.Rd b/man/autoplot.LearnerRegr.Rd index 8a6dff44..3462382c 100644 --- a/man/autoplot.LearnerRegr.Rd +++ b/man/autoplot.LearnerRegr.Rd @@ -47,10 +47,6 @@ Possible choices are: } \examples{ \donttest{ -if (requireNamespace("mlr3")) { -library(mlr3) -library(mlr3viz) - task = tsk("mtcars")$select(c("am", "carb")) learner = lrn("regr.rpart") learner$train(task) @@ -58,4 +54,3 @@ learner$train(task) autoplot(learner, type = "prediction", task) } } -} diff --git a/man/autoplot.OptimInstanceBatchSingleCrit.Rd b/man/autoplot.OptimInstanceBatchSingleCrit.Rd index 4eb081ce..92b672d5 100644 --- a/man/autoplot.OptimInstanceBatchSingleCrit.Rd +++ b/man/autoplot.OptimInstanceBatchSingleCrit.Rd @@ -70,44 +70,43 @@ The y values are interpolated with the supplied \link[mlr3:Learner]{mlr3::Learne } } \examples{ -if (requireNamespace("mlr3") && requireNamespace("bbotk") && requireNamespace("patchwork")) { - library(bbotk) - library(paradox) - - fun = function(xs) { - c(y = -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10) - } - domain = ps( - x1 = p_dbl(-10, 10), - x2 = p_dbl(-5, 5) - ) - codomain = ps( - y = p_dbl(tags = "maximize") - ) - obfun = ObjectiveRFun$new( - fun = fun, - domain = domain, - codomain = codomain - ) - - instance = oi(objective = obfun, terminator = trm("evals", n_evals = 20)) - - optimizer = opt("random_search", batch_size = 2) - optimizer$optimize(instance) - - # plot y versus batch number - print(autoplot(instance, type = "performance")) - - # plot x1 values versus performance - print(autoplot(instance, type = "marginal", cols_x = "x1")) - - # plot parallel coordinates plot - print(autoplot(instance, type = "parallel")) - - # plot pairs - print(autoplot(instance, type = "pairs")) - - # plot incumbent - print(autoplot(instance, type = "incumbent")) +if (mlr3misc::require_namespaces(c("paradox", "bbotk", "patchwork"), quietly = TRUE)) { +library(bbotk) + +fun = function(xs) { + c(y = -(xs[[1]] - 2)^2 - (xs[[2]] + 3)^2 + 10) +} +domain = ps( + x1 = p_dbl(-10, 10), + x2 = p_dbl(-5, 5) +) +codomain = ps( + y = p_dbl(tags = "maximize") +) +obfun = ObjectiveRFun$new( + fun = fun, + domain = domain, + codomain = codomain +) + +instance = oi(objective = obfun, terminator = trm("evals", n_evals = 20)) + +optimizer = opt("random_search", batch_size = 2) +optimizer$optimize(instance) + +# plot y versus batch number +print(autoplot(instance, type = "performance")) + +# plot x1 values versus performance +print(autoplot(instance, type = "marginal", cols_x = "x1")) + +# plot parallel coordinates plot +print(autoplot(instance, type = "parallel")) + +# plot pairs +print(autoplot(instance, type = "pairs")) + +# plot incumbent +print(autoplot(instance, type = "incumbent")) } } diff --git a/man/autoplot.PredictionClassif.Rd b/man/autoplot.PredictionClassif.Rd index 9bf5dc2f..99b53ccf 100644 --- a/man/autoplot.PredictionClassif.Rd +++ b/man/autoplot.PredictionClassif.Rd @@ -44,18 +44,15 @@ Requires package \CRANpkg{precrec}. } \examples{ \donttest{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3viz) +if (mlr3misc::require_namespaces("precrec", quietly = TRUE)) { +task = tsk("spam") +learner = lrn("classif.rpart", predict_type = "prob") +object = learner$train(task)$predict(task) - task = tsk("spam") - learner = lrn("classif.rpart", predict_type = "prob") - object = learner$train(task)$predict(task) - - head(fortify(object)) - autoplot(object) - autoplot(object, type = "roc") - autoplot(object, type = "prc") +head(fortify(object)) +autoplot(object) +autoplot(object, type = "roc") +autoplot(object, type = "prc") } } } diff --git a/man/autoplot.PredictionClust.Rd b/man/autoplot.PredictionClust.Rd index c493f251..782fd5a8 100644 --- a/man/autoplot.PredictionClust.Rd +++ b/man/autoplot.PredictionClust.Rd @@ -45,17 +45,15 @@ Inspired by and uses \link[ggfortify:autoplot.kmeans]{ggfortify::autoplot.kmeans } } \examples{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3cluster) - library(mlr3viz) +if (mlr3misc::require_namespaces(c("clue", "mlr3cluster"), quietly = TRUE)) { +library(mlr3cluster) - task = tsk("usarrests") - learner = lrn("clust.kmeans", centers = 3) - object = learner$train(task)$predict(task) +task = tsk("usarrests") +learner = lrn("clust.kmeans", centers = 3) +object = learner$train(task)$predict(task) - head(fortify(object)) - autoplot(object, task) +head(fortify(object)) +autoplot(object, task) } } \references{ diff --git a/man/autoplot.PredictionRegr.Rd b/man/autoplot.PredictionRegr.Rd index ad67a7ad..1302609b 100644 --- a/man/autoplot.PredictionRegr.Rd +++ b/man/autoplot.PredictionRegr.Rd @@ -51,24 +51,20 @@ possible with \code{predict_type = "se"}. \code{geom_abline()} with \code{slope } } \examples{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3viz) +if (mlr3misc::require_namespaces("mlr3learners", quietly = TRUE)) { +library(mlr3learners) - task = tsk("mtcars") - learner = lrn("regr.rpart") - object = learner$train(task)$predict(task) +task = tsk("mtcars") +learner = lrn("regr.rpart") +object = learner$train(task)$predict(task) - head(fortify(object)) - autoplot(object) - autoplot(object, type = "histogram", binwidth = 1) - autoplot(object, type = "residual") +head(fortify(object)) +autoplot(object) +autoplot(object, type = "histogram", binwidth = 1) +autoplot(object, type = "residual") - if (requireNamespace("mlr3learners")) { - library(mlr3learners) - learner = lrn("regr.ranger", predict_type = "se") - object = learner$train(task)$predict(task) - autoplot(object, type = "confidence") - } +learner = lrn("regr.ranger", predict_type = "se") +object = learner$train(task)$predict(task) +autoplot(object, type = "confidence") } } diff --git a/man/autoplot.ResampleResult.Rd b/man/autoplot.ResampleResult.Rd index 99104fe7..bf15e23e 100644 --- a/man/autoplot.ResampleResult.Rd +++ b/man/autoplot.ResampleResult.Rd @@ -62,37 +62,34 @@ For tasks with two features the predict type will be ignored. } \examples{ \donttest{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3viz) +if (mlr3misc::require_namespaces("precrec", quietly = TRUE)) { +task = tsk("sonar") +learner = lrn("classif.rpart", predict_type = "prob") +resampling = rsmp("cv", folds = 3) +object = resample(task, learner, resampling) - task = tsk("sonar") - learner = lrn("classif.rpart", predict_type = "prob") - resampling = rsmp("cv", folds = 3) - object = resample(task, learner, resampling) +head(fortify(object)) - head(fortify(object)) +# Default: boxplot +autoplot(object) - # Default: boxplot - autoplot(object) +# Histogram +autoplot(object, type = "histogram", bins = 30) - # Histogram - autoplot(object, type = "histogram", bins = 30) +# ROC curve, averaged over resampling folds: +autoplot(object, type = "roc") - # ROC curve, averaged over resampling folds: - autoplot(object, type = "roc") +# ROC curve of joint prediction object: +autoplot(object$prediction(), type = "roc") - # ROC curve of joint prediction object: - autoplot(object$prediction(), type = "roc") +# Precision Recall Curve +autoplot(object, type = "prc") - # Precision Recall Curve - autoplot(object, type = "prc") - - # Prediction Plot - task = tsk("iris")$select(c("Sepal.Length", "Sepal.Width")) - resampling = rsmp("cv", folds = 3) - object = resample(task, learner, resampling, store_models = TRUE) - autoplot(object, type = "prediction") +# Prediction Plot +task = tsk("iris")$select(c("Sepal.Length", "Sepal.Width")) +resampling = rsmp("cv", folds = 3) +object = resample(task, learner, resampling, store_models = TRUE) +autoplot(object, type = "prediction") } } } diff --git a/man/autoplot.TaskClassif.Rd b/man/autoplot.TaskClassif.Rd index 3444e44d..79b7a77d 100644 --- a/man/autoplot.TaskClassif.Rd +++ b/man/autoplot.TaskClassif.Rd @@ -33,16 +33,12 @@ Color is set to target column. } } \examples{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3viz) +if (mlr3misc::require_namespaces("GGally", quietly = TRUE)) { +task = tsk("iris") - task = tsk("iris") - - head(fortify(task)) - autoplot(task) - autoplot(task$clone()$select(c("Sepal.Length", "Sepal.Width")), - type = "pairs") - autoplot(task, type = "duo") +head(fortify(task)) +autoplot(task) +autoplot(task$clone()$select(c("Sepal.Length", "Sepal.Width")), type = "pairs") +autoplot(task, type = "duo") } } diff --git a/man/autoplot.TaskClust.Rd b/man/autoplot.TaskClust.Rd index 3675545f..e37c7c4b 100644 --- a/man/autoplot.TaskClust.Rd +++ b/man/autoplot.TaskClust.Rd @@ -29,14 +29,11 @@ Possible choices are: } } \examples{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3cluster) - library(mlr3viz) +if (mlr3misc::require_namespaces("mlr3cluster", quietly = TRUE)) { +library(mlr3cluster) +task = tsk("usarrests") - task = mlr_tasks$get("usarrests") - - head(fortify(task)) - autoplot(task) +head(fortify(task)) +autoplot(task) } } diff --git a/man/autoplot.TaskRegr.Rd b/man/autoplot.TaskRegr.Rd index 7313ad9c..3821d459 100644 --- a/man/autoplot.TaskRegr.Rd +++ b/man/autoplot.TaskRegr.Rd @@ -31,15 +31,12 @@ Color is set to target column. } } \examples{ -if (requireNamespace("mlr3")) { - library(mlr3) - library(mlr3viz) +if (mlr3misc::require_namespaces("GGally", quietly = TRUE)) { +task = tsk("mtcars") +task$select(c("am", "carb")) - task = tsk("mtcars") - task$select(c("am", "carb")) - - head(fortify(task)) - autoplot(task) - autoplot(task, type = "pairs") +head(fortify(task)) +autoplot(task) +autoplot(task, type = "pairs") } } diff --git a/man/autoplot.TuningInstanceBatchSingleCrit.Rd b/man/autoplot.TuningInstanceBatchSingleCrit.Rd index 7cc948d1..a9961d1b 100644 --- a/man/autoplot.TuningInstanceBatchSingleCrit.Rd +++ b/man/autoplot.TuningInstanceBatchSingleCrit.Rd @@ -65,37 +65,37 @@ The y values are interpolated with the supplied \link[mlr3:Learner]{mlr3::Learne } } \examples{ -if (requireNamespace("mlr3tuning") && requireNamespace("patchwork")) { - library(mlr3tuning) +if (mlr3misc::require_namespaces(c("mlr3tuning", "patchwork", "paradox"), quietly = TRUE)) { +library(mlr3tuning) - learner = lrn("classif.rpart") - learner$param_set$values$cp = to_tune(0.001, 0.1) - learner$param_set$values$minsplit = to_tune(1, 10) +learner = lrn("classif.rpart") +learner$param_set$values$cp = to_tune(0.001, 0.1) +learner$param_set$values$minsplit = to_tune(1, 10) - instance = ti( - task = tsk("iris"), - learner = learner, - resampling = rsmp("holdout"), - measure = msr("classif.ce"), - terminator = trm("evals", n_evals = 10)) +instance = ti( + task = tsk("iris"), + learner = learner, + resampling = rsmp("holdout"), + measure = msr("classif.ce"), + terminator = trm("evals", n_evals = 10)) - tuner = tnr("random_search") +tuner = tnr("random_search") - tuner$optimize(instance) +tuner$optimize(instance) - # plot performance versus batch number - autoplot(instance, type = "performance") +# plot performance versus batch number +autoplot(instance, type = "performance") - # plot cp values versus performance - autoplot(instance, type = "marginal", cols_x = "cp") +# plot cp values versus performance +autoplot(instance, type = "marginal", cols_x = "cp") - # plot transformed parameter values versus batch number - autoplot(instance, type = "parameter", trafo = TRUE) +# plot transformed parameter values versus batch number +autoplot(instance, type = "parameter", trafo = TRUE) - # plot parallel coordinates plot - autoplot(instance, type = "parallel") +# plot parallel coordinates plot +autoplot(instance, type = "parallel") - # plot pairs - autoplot(instance, type = "pairs") +# plot pairs +autoplot(instance, type = "pairs") } } diff --git a/tests/testthat/teardown.R b/tests/testthat/teardown.R index 6ed02f88..b51d98bc 100644 --- a/tests/testthat/teardown.R +++ b/tests/testthat/teardown.R @@ -1,2 +1,6 @@ -lg$set_threshold(old_threshold) +if (requireNamespace("lgr")) { + lg = lgr::get_logger("mlr3") + lg$set_threshold(old_threshold) +} + setDTthreads(old_dt_threads) diff --git a/tests/testthat/test_BenchmarkResult.R b/tests/testthat/test_BenchmarkResult.R index 8010b689..c13f38b8 100644 --- a/tests/testthat/test_BenchmarkResult.R +++ b/tests/testthat/test_BenchmarkResult.R @@ -19,6 +19,7 @@ test_that("autoplot BenchmarkResult", { expect_true(is_ggplot(p)) expect_doppelganger("bmr_boxplot", p) + skip_if_not_installed("precrec") expect_error(autoplot(bmr, type = "roc"), "multiple") object = bmr$clone(deep = TRUE)$filter(task_ids = "sonar") @@ -33,6 +34,7 @@ test_that("autoplot BenchmarkResult", { }) test_that("holdout roc plot (#54)", { + skip_if_not_installed("precrec") tasks = tsks("german_credit") learners = c("classif.featureless", "classif.rpart") diff --git a/tests/testthat/test_Filter.R b/tests/testthat/test_Filter.R index fe5943e4..ef84e776 100644 --- a/tests/testthat/test_Filter.R +++ b/tests/testthat/test_Filter.R @@ -1,4 +1,4 @@ -skip_if_not_installed("mlr3") +skip_if_not_installed("mlr3filters") test_that("autoplot.Filter", { task = mlr3::tsk("iris") diff --git a/tests/testthat/test_LearnerClassif.R b/tests/testthat/test_LearnerClassif.R index 8c61f34b..87eb63a6 100644 --- a/tests/testthat/test_LearnerClassif.R +++ b/tests/testthat/test_LearnerClassif.R @@ -1,3 +1,5 @@ +skip_if_not_installed("mlr3") + test_that("autoplot.PredictionClassif decision boundary probability", { set.seed(42) task = mlr3::tsk("pima")$select(c("age", "pedigree")) diff --git a/tests/testthat/test_LearnerRegr.R b/tests/testthat/test_LearnerRegr.R index 455d7e1a..73c6b8cc 100644 --- a/tests/testthat/test_LearnerRegr.R +++ b/tests/testthat/test_LearnerRegr.R @@ -1,3 +1,5 @@ +skip_if_not_installed("mlr3") + test_that("autoplot.PredictionRegr decision boundary 1D", { set.seed(42) task = mlr3::tsk("mtcars")$select("am") diff --git a/tests/testthat/test_PredictionClassif.R b/tests/testthat/test_PredictionClassif.R index 45b77c73..5d1d972c 100644 --- a/tests/testthat/test_PredictionClassif.R +++ b/tests/testthat/test_PredictionClassif.R @@ -10,6 +10,7 @@ test_that("autoplot.PredictionClassif", { expect_true(is_ggplot(p)) expect_doppelganger("predictionclassif_stacked", p) + skip_if_not_installed("precrec") p = autoplot(prediction, type = "roc") expect_true(is_ggplot(p)) expect_doppelganger("predictionclassif_roc", p) diff --git a/tests/testthat/test_ResampleResult.R b/tests/testthat/test_ResampleResult.R index fee375e3..696adf53 100644 --- a/tests/testthat/test_ResampleResult.R +++ b/tests/testthat/test_ResampleResult.R @@ -24,6 +24,7 @@ test_that("autoplot ResampleResult", { expect_true(is_ggplot(p)) expect_doppelganger("resampleresult_histogram", p) + skip_if_not_installed("precrec") p = autoplot(rr, type = "roc") expect_true(is_ggplot(p)) expect_doppelganger("resampleresult_roc", p) @@ -84,8 +85,8 @@ regression!") test_that("roc is not inverted", { - autoplot(rr, type = "roc") skip_if_not_installed("precrec") + autoplot(rr, type = "roc") tab = as.data.table(precrec::auc(precrec::evalmod(as_precrec(rr)))) expect_number(mean(tab[curvetypes == "ROC", aucs]), lower = 0.5) }) diff --git a/tests/testthat/test_TaskClassif.R b/tests/testthat/test_TaskClassif.R index 902e942f..7b4297a8 100644 --- a/tests/testthat/test_TaskClassif.R +++ b/tests/testthat/test_TaskClassif.R @@ -7,6 +7,7 @@ test_that("autoplot.TaskClassif", { expect_true(is_ggplot(p)) expect_doppelganger("taskclassif_target", p) + skip_if_not_installed("GGally") p = autoplot(task, type = "pairs") expect_s3_class(p, "ggmatrix") expect_doppelganger("taskclassif_pairs", p) diff --git a/tests/testthat/test_TaskRegr.R b/tests/testthat/test_TaskRegr.R index 9670f9a5..9ffadbf4 100644 --- a/tests/testthat/test_TaskRegr.R +++ b/tests/testthat/test_TaskRegr.R @@ -7,6 +7,7 @@ test_that("autoplot.TaskRegr", { expect_true(is_ggplot(p)) expect_doppelganger("taskregr_target", p) + skip_if_not_installed("GGally") p = autoplot(task, type = "pairs") expect_s3_class(p, "ggmatrix") expect_doppelganger("taskregr_pairs", p)