mlr-org / mlr3misc

Miscellaneous helper functions for mlr3
https://mlr3misc.mlr-org.com
GNU Lesser General Public License v3.0
11 stars 2 forks source link

Partial argument matching for dictionary sugar get #83

Closed sebffischer closed 7 months ago

sebffischer commented 1 year ago

It is e.g. impossible for a learner with a parameter / field that partially matches dict to be set during a lrn() call as the value of this parameter will be used as the dict argument.

mllg commented 1 year ago

Can you provide a reproducible example for this?

sebffischer commented 1 year ago
library(mlr3misc)

dictionary = Dictionary$new()

dictionary$add("a", function(di) print(dictus))

sgr = function(.key, ...) {
  dictionary_sugar_get(dictionary, .key, ...)
}

sgr("a", di = "hallo")
#> Error in dictionary_sugar_get(dictionary, .key, ...): Assertion on 'dict' failed: Must inherit from class 'Dictionary', but has class 'character'.

Created on 2023-07-06 with reprex v2.0.2

sebffischer commented 1 year ago

The additional di = "hallo" partially matches the dict argument from dictionary_sugar_get. We could just call the dict argument .dict.

mllg commented 1 year ago

Agreed - can you PR this?

sebffischer commented 1 year ago

We need to sync package releases though: https://github.com/mlr-org/mlr3pipelines/blob/dae03afd8efa83621a495a058f42cfc2ea8d7357/R/ppl.R#L26

Or we add an

if (packageVersion("mlr3") > ...) 
  use .dict
else
  use dict

to the relevant functions

mb706 commented 1 year ago

maybe better to create a new function dictionary_sugar_get_safe and remove the old function after a few versions, this way we don't all have to upload new packages