mllg / batchtools

Tools for computation on batch systems
https://mllg.github.io/batchtools/
GNU Lesser General Public License v3.0
172 stars 51 forks source link

Jobs with calls to withr::with_options(NULL, ...) crash #195

Closed renozao closed 6 years ago

renozao commented 6 years ago

Here is a minimal example:

library(batchtools)
reg <- makeExperimentRegistry(file.dir = NA)
addProblem(name = "pb", data = 1)
algo <- function(data, job, instance, ...){
  print("start")
  withr::with_options(NULL, {print("in with_options")})
  print("done")
  10

}
addAlgorithm(name = "algo", fun = algo)
addExperiments(prob.designs = NULL, algo.designs = NULL)

# a direct call to the function works 
algo()

# when run as a job it breaks
testJob(id = 1)

The error thrown is:

Error in (function (...)  : invalid value for 'error'
15: (function (e) 
    traceback(2L))()
14: (function (...) 
    .Internal(options(...)))(add.smooth = TRUE, ambiguousMethodSelection = function (cond) 

Replacing NULL by list(a = 1) in the call to withr::with_options does not throw the error, and the code works as expected.

I am under Ubuntu but the same behavior happens under Windows. Package versions are:

batchtools       0.9.8      2017-12-15 CRAN (R 3.4.2)
withr            2.1.2      2018-03-15 CRAN (R 3.4.4)
mllg commented 6 years ago

This is related to https://github.com/r-lib/withr/issues/73, right? I'll give @jimhester some more time to deal with this upstream before implementing workarounds here.

renozao commented 6 years ago

Possibly yes. I imagine that having options = NULL here is also a bit a of an edge case. I'll await for a fix for r-lib/withr#73 and see. Can you please also update this thread once you tested the fix? Thanks

mllg commented 6 years ago

Can you please also update this thread once you tested the fix?

Sure.

mllg commented 6 years ago

This problem has been fixed upstream, your reprex works now. Let me know if you encounter any further issues.