mlr-org / mlr

Machine Learning in R
https://mlr.mlr-org.com
Other
1.64k stars 405 forks source link

Should listLearners() fail if RWeka is not installed? #2715

Closed Robinlovelace closed 4 years ago

Robinlovelace commented 4 years ago

See here for context: https://github.com/Robinlovelace/geocompr/issues/459#issuecomment-573436563

This made Geocomputation with R code crash I think...

Thanks.

larskotthoff commented 4 years ago

listLearners() will only list the learners that are available, i.e. if RWeka isn't installed, none of its learners will be listed. This isn't an error.

pat-s commented 4 years ago

Thanks. @larskotthoff Runing the code shows clearly an error and @Robinlovelace is right here that it shouldn't fail if the package is not available. There is even the explicit arg check.packages.

The reason for the error comes from

https://github.com/mlr-org/mlr/blob/3d7e0aa91936e82cf108aff3c46b19e3f953eefd/R/RLearner_classif_adaboostm1.R#L12-L12

When pkg::fun is called in the ParamSet, we implicitly require the package. I came across this just recently in a similar way for an FDA learner.

Correct behavior should look as follows (where {rpart} is missing)

library(mlr)
#> Loading required package: ParamHelpers
#> 'mlr' is in maintenance mode since July 2019. Future development
#> efforts will go into its successor 'mlr3' (<https://mlr3.mlr-org.com>).

foo = listLearners(iris.task, check.packages = FALSE, warn.missing.packages = TRUE)
#> Warning in listLearners.character(td$type, union(props, properties), quiet, : The following learners could not be constructed, probably because their packages are not installed:
#> classif.ada,classif.boosting,classif.bst,classif.classiFunc.kernel,classif.classiFunc.knn,classif.rpart,regr.bst,regr.rpart,surv.rpart
#> Check ?learners to see which packages you need or install mlr with all suggestions.

Created on 2020-01-12 by the reprex package (v0.3.0)

I'll push a fix in the next days. Thanks for reporting!

larskotthoff commented 4 years ago

Ah sorry, I misunderstood the issue as the opposite of what it was!