Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parsnip's "Model already registered" error prevents attaching packages with custom models to fit_resamples and tune_grid #1260

Open
chillerb opened this issue Feb 20, 2025 · 0 comments

Comments

@chillerb
Copy link

Hello, it's me again! 🥳

So, here is the scenario: I have a package that registers custom parsnip models .onLoad, and also exports a custom yardstick metric for evaluation as S3method.

Now, I want to call:

library(tidymodels)
library(my_pkg)

plan(multisession)

...

cv_res <- fit_resamples(my_model, y ~ x, cv_splits, metrics = my_metric)

However, this fails, because my custom metric my_metric isn't available in the workers' environments.

Ok, so what about explicitly attaching my package then?

library(tidymodels)
library(my_pkg)

plan(multisession)

...

cv_res <- fit_resamples(my_model, y ~ x, cv_splits, metrics = my_metric, control = control_resamples(pkgs = "my_pkg"))

This fails too - this time, because on load, my_pkgs tries to register the custom parsnip model again. However, the workers apparently receive the hidden parsnip registry object, causing parsnip to throw a "Model already exists" error.

Is there is a good solution to this problem at the moment?
parsnip:::check_model_doesnt_exist is not exported, so the obvious route of checking in .onLoad is not available.
I think, for now, I will just wrap the set_new_model calls with try?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant