mlr-org / mlr3pipelines

Dataflow Programming for Machine Learning in R
https://mlr3pipelines.mlr-org.com/
GNU Lesser General Public License v3.0
137 stars 25 forks source link

R 4.2.0: first argument has length > 1 error #661

Closed pat-s closed 2 years ago

pat-s commented 2 years ago

Ref: https://github.com/mlr-org/mlr3spatiotempcv/issues/170

library(mlr3)
library(mlr3learners)
library(mlr3pipelines)
library(mlr3spatiotempcv) # package is loaded but never used
library(paradox)

task <- tsk("mtcars")
learner_lm <- lrn("regr.lm")

g_ppl = ppl("targettrafo", graph = learner_lm)
g_ppl$param_set$values$targetmutate.trafo = function(x) log(x)
g_ppl$param_set$values$targetmutate.inverter = function(x) list(response = exp(x$response))

g_lrn <- GraphLearner$new(g_ppl)
g_lrn$train(task)
g_lrn$predict(task)
#> Error in get(mlr_reflections$task_types[type]$prediction): first argument has length > 1
#> This happened PipeOp targetinvert's $predict()

Created on 2022-04-28 by the reprex package (v2.0.1)

Context

R 4.2.0 is stricter WRT to sloppy subsetting. {mlr3spatiotempcv} adds an entry to mlr_reflections$task_types which let's the follwing subset calls in {mlr3pipelines} throw the error reported above. There might be possibly more such instances in all of our pkgs which just turn into errors now (as of R 4.2.0).

https://github.com/mlr-org/mlr3pipelines/blob/e55b0a93b11c109534d5fd1db3b0d47a0a7e53ed/R/PipeOpTrafo.R#L385

https://github.com/mlr-org/mlr3pipelines/blob/e55b0a93b11c109534d5fd1db3b0d47a0a7e53ed/R/PipeOpRandomResponse.R#L124-L124

Possible solutions:

pat-s commented 2 years ago

@s-kganz You have the following options:

s-kganz commented 2 years ago

@pat-s RE option 3: awww, but it's so much fun! :)

I'll use the hotfix for now, I appreciate your quick response!

mb706 commented 2 years ago

Closed by #662