Skip to content

Fix tune_args() error with namespaced function arguments (#261)#262

Open
EmilHvitfeldt wants to merge 3 commits into
mainfrom
fix-261-namespaced-arg
Open

Fix tune_args() error with namespaced function arguments (#261)#262
EmilHvitfeldt wants to merge 3 commits into
mainfrom
fix-261-namespaced-arg

Conversation

@EmilHvitfeldt

Copy link
Copy Markdown
Member

Fixes #261.

Problem

Setting a model argument to a namespaced function, e.g. hier_clust(num_clusters = tune(), dist_fun = philentropy::distance), caused tune_cluster() / tune_args() to error with argument is of length zero.

The argument expression pkg::fun is a :: call, for which rlang::call_name() returns NULL. The check rlang::call_name(x) == "tune" then became NULL == "tune", which is length-zero and errors inside if().

Fix

In tune_id(), capture the call name once and guard against NULL:

nm <- rlang::call_name(x)
if (!is.null(nm) && nm == "tune") {

Added a test confirming tune_args() works with dist_fun = stats::dist, and a NEWS bullet.

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

Successfully merging this pull request may close these issues.

Specifying a distance function in hier_clust() breaks the ability to "tune" it

1 participant