Error in callr subprocess: DMatrix/Booster has not been initialized or has already been disposed in R

Issue

This Content is from Stack Overflow. Question asked by MariosCh1

In my R Shiny application, I implemented a cross-validation model using the xgb.cv() and everything worked fine. Then I added the r_bg() function in order to make a multiple process since I needed the Start/Stop ability. After this addition, I face an issue when I pass the DMatrix to the args=list() of r_bg(). Specifically, a DMatrix is required for the xgb.cv() model which has to be passed in the r_bg() and I get the error:

Warning: Error in : ! error in callr subprocess
Caused by error in `getinfo.xgb.DMatrix(data, "label")`:
! [14:17:28] amalgamation/../src/c_api/c_api.cc:571: DMatrix/Booster has not been initialized or has already been disposed.

Below you can find my code for the data transformation to DMatrix structure as well as the part of the start training process:

Server Code:

server <-  function(input, output, session) {

observe({

      req(input$checkbox_regression_choice)
      req(input$select_dependent_variable)
      req(input$select_independent_variables)


      values$train_data_x <- data.matrix(subset(values$train_partition, select = input$select_independent_variables))
      values$train_label_y <- values$train_partition[[input$select_dependent_variable]]

      values$test_data_x <- data.matrix(subset(values$test_partition, select = input$select_independent_variables))
      values$test_label_y <- values$test_partition[[input$select_dependent_variable]]

      values$xgb_train <- xgb.DMatrix(data = values$train_data_x.append(), label = values$train_label_y)
      values$xgb_test <- xgb.DMatrix(data = values$test_data_x, label = values$test_label_y)

        })

observeEvent(input$ML_Submit_Button,{
  
  shinyjs::hide("ML_Submit_Button")
  shinyjs::show("ML_Stop_Button")

  values$bg_process <- r_bg(xgb_gs_cv_regression, 
                        args = list(xgb_train = values$xgb_train, 
                                    subsample_choice = values$subsample_slider_seq, 
                                    colsample_bytree_choice = values$colsample_bytree_slider_seq, 
                                    max_depth_choice = values$max_depth_slider_seq, 
                                    min_child_weight_choice = values$min_child_weight_slider_seq, 
                                    eta_choice = values$eta_slider_seq, 
                                    n_rounds_choice = values$n_rounds_slider_seq, 
                                    n_fold_choice = values$n_fold_slider_seq),
                        stdout = "|", 
                        stderr = "2>&1")

})

}

Could you advise me how to overcome this error?



Solution

This question is not yet answered, be the first one who answer using the comment. Later the confirmed answer will be published as the solution.

This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 2.5. - CC BY-SA 3.0. - CC BY-SA 4.0.

people found this article helpful. What about you?