Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

scoping errors depending on objects in global environment #275

Open
sumny opened this issue Jun 15, 2021 · 0 comments
Open

scoping errors depending on objects in global environment #275

sumny opened this issue Jun 15, 2021 · 0 comments

Comments

@sumny
Copy link

sumny commented Jun 15, 2021

I recently stumbled across the following rather weird behavior:
If a custom function named eval is present in my .GlobalEnv, testing jobs with external = TRUE and potentially also submitting will fail:

library(batchtools)  # 0.9.15
library(data.table)

reg = makeExperimentRegistry(file.dir = NA, seed = 1)

addProblem(name = "test", fun = function(...) list(...), seed = 2)

eval_ = function(data, job, instance, ...) {
  xs = list(...)
  1 + xs$x1
}

eval = function(...) list(...)

addAlgorithm(name = "eval_", fun = eval_)

pdes = list(test = data.table())
ades = list(eval_ = data.table(x1 = c(1, 2)))
addExperiments(pdes, ades, repls = 1)

testJob(1)
#### [bt]: Generating problem instance for problem 'test' ...
#### [bt]: Applying algorithm 'eval_' on problem 'test' for job 1 (seed = 2) ...
#[1] 2

testJob(1, external = TRUE)
# Error: testJob() failed for job with id=1. To properly debug, re-run with external=FALSE

rm(eval)

testJob(1, external = TRUE)
### [bt]: Generating problem instance for problem 'test' ...
### [bt]: Applying algorithm 'eval_' on problem 'test' for job 1 (seed = 2) ...
[1] 2

Initially, the algorithm was named eval and I thought this caused the problem, however, it seems like it suffices to have a custom function eval present in the .GlobalEnv. My initial guess would be that this interferes with properly scoping base::eval at some later stages (not sure why though).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant