Passing R CMD check when adding case weights to the tidymodels workflow

Hello!

I'm developing a package where users will be allowed to pass in a tidymodels workflow, a dataset, and a set of case weights to a function. The function will then add the case weights to the dataset, split the data into a training and testing set, train the hyperparameters (if there are any), update the workflow to reflect the hyperparameters, and fit the final model. I've included a reprex below. The function is working as intended. The reprex is really just to provid context for my issue.

The problem I'm having is that the function is being flagged by R CMD check, specifically for workflows::add_case_weights(case_wts). My question that I'm hoping you can help me with: what do I need to do for that line of code to not generate a note of fit_ml: no visible binding for global variable ‘case_wts’ during R CMD check?

Thanks!
Jeff

user_workflow <-
  parsnip::rand_forest(mtry = 1,
                       trees = parsnip::tune(),
                       min_n = parsnip::tune()) |>
  parsnip::set_mode("classification") |>
  parsnip::set_engine("ranger")

dat <- mtcars |> 
  tibble::as_tibble() |> 
  dplyr::select("cyl", "vs", "am", "gear", "carb") |> 
  dplyr::mutate(cyl = factor(.data$cyl, levels = c(4, 6, 8)),
                vs = factor(.data$vs, levels = c(0, 1)),
                am = factor(.data$am, levels = c(0, 1)),
                gear = factor(.data$gear, levels = c(3, 4, 5)),
                carb = factor(.data$carb, levels = c(1, 2, 3, 4, 6, 8)))
weights <- runif(nrow(dat))

fit_ml <- function(
    user_workflow,
    dat,
    weights
) {
  dat <- dat |> 
    dplyr::mutate(case_wts = hardhat::importance_weights(weights))
  
  data_split <- rsample::initial_split(dat, prop = .90)
  train_data <- rsample::training(data_split)
  test_data <- rsample::testing(data_split)
  
  mod_recipe <-
    recipes::recipe(cyl ~ .,
                    data = train_data)
  
  mod_wf <-
    workflows::workflow() |>
    workflows::add_recipe(mod_recipe) |>
    workflows::add_model(user_workflow) |>
    workflows::add_case_weights(case_wts)
  
  mod_folds <- rsample::vfold_cv(train_data)
  
  doParallel::registerDoParallel()
  
  suppressWarnings(
    suppressMessages(
      mod_tune <-
        tune::tune_grid(mod_wf,
                        resamples = mod_folds,
                        grid = 10)
    )
  )
  
  hyperparameters <- tune::select_best(mod_tune, metric = "roc_auc")
  
  tuned_mod <- tune::finalize_model(user_workflow, hyperparameters)
  
  final_wf <-
    workflows::workflow() |>
    workflows::add_recipe(mod_recipe) |>
    workflows::add_model(tuned_mod) |>
    workflows::add_case_weights(case_wts)

  mod_fit <-
    final_wf |>
    workflows::fit(data = train_data)  
}

See e.g. here: https://stackoverflow.com/a/63877974