14

Having an issue while running a logistic regression model using caret::train(). LR = caret::train(Satisfaction ~., data= log_train, method = "glm", preProcess = c("scale"), family="binomial")

keep getting the following line of error:

Error in summary.connection(connection) : invalid connection

This error seems new to me as when i had previously run this code, i did not see any issue. Please help!

StupidWolf
  • 45,075
  • 17
  • 40
  • 72
Manasi bhargav
  • 141
  • 1
  • 1
  • 3

1 Answers1

31

I got this error because of an issue with the parallel computing back-end for foreach/dopar. You may have some parallel computing going on in the background that is not getting cleaned up fully between runs. The easiest way I have found to fix it is to call this function:

unregister_dopar <- function() {
  env <- foreach:::.foreachGlobals
  rm(list=ls(name=env), pos=env)
}

This function is from Steve Weston's accepted answer in this thread: "un-register" a doParallel cluster

KRBundy
  • 411
  • 4
  • 4
  • This is a great solution as I have been dealing with this issue for nearly two years without finding a solution. I do have a question however, if I register this function, do I then run "unregister_dopar" in a single line by itself before I run the foreach loop, or do I put this in or even after the loop? Thanks! – CooperBuckeye05 Oct 13 '21 at 22:43