Alternating errors using case_weights in workflows

Hi,

I have been using the use_case_weights function for a couple of months and I keep running into errors that I find difficult to understand and also to reproduce. The problem is that the same code could work perfectly fine 9 out of 10 times perfectly and then cause R studio to abort on the 10th run.
Also FYI, the code works 100% of the time without the case weights.

Some info: I'm using R 4.2.1, all packages are updated to the latest version.
This is my reprex - sorry if I'm not using the reprex package but I can't get it to work since R studio crashes when the errors come up.

require(dplyr)
require(workflows)
require(rsample)
require(recipes)
require(tune)
require(yardstick)
require(hardhat)

data("randu")
randu$weight = runif(400)
randu = randu %>% mutate(weight = importance_weights(weight))

for(i in 1:20){
    print(i)
cv <- vfold_cv(randu, v=3)
recipe <- recipe(x ~ ., data = randu)

# model
gbt = boost_tree() %>%
        set_args(
            tree_depth = tune(),
            learn_rate = tune()
        ) %>%
        set_engine("xgboost") %>%
        set_mode("regression")

gbt_grid = expand.grid(
        tree_depth = 1:5,
        learn_rate = seq(0.05, 0.5,length.out = 10)
    )

w1 = workflow() %>% 
    add_case_weights(weight)%>% 
    add_recipe(recipe) %>% 
    add_model(gbt) 
print("tuning gbt")
w1_res = w1 %>% 
    tune_grid(grid = gbt_grid, resamples = cv,
                    metrics = metric_set(rmse))

}

As I said, the above code works fine 90% of the time, that's why I put a for loop, so that at least it creashes once. I have received the following three different messages before crashing:

x: preprocessor 1/1:
Error in vec_equal():
! Can't combine '..1' < character > and '..2' < importance_weights >

Error in { :
'kind' must be a character string of length 1 (RNG is used)

x: internal:
Error in dplyr::bind_cols():
! Unexpected type 'logical'.
i in file type-data-frame.c at line 415
i This is an internal error in the vctrs package, please report it to the package authors.

I don't know how to interpret these errors, it seems to me like there's some type conflict somewhere with the importance weights.

Hope that helps!

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.