Closed HenrikBengtsson closed 6 years ago
UPDATE: I've now turned on run.dontrun = TRUE
for all example()
:s and example("avNNet", package = "caret", run.dontrun = TRUE)
is the only one that gives an error.
A minimal reproducible example of this issue that does not require the caret
package:
reset <- FALSE
x <- 1
foreach(i = 1L) %dopar% {
if (reset) x <- 0
x + 1
}
## Error in { : task 1 failed - "object 'x' not found"
As a reference, same happens with:
reset <- FALSE
x <- 1
future_lapply(1L, function(i) {
if (reset) x <- 0
x + 1
})
This is now fixed in the develop branch of doFuture. Until these updates reach CRAN, it can be installed using:
remotes::install_github("HenrikBengtsson/doFuture@develop")
Thanks @hanase for bring this one to my attention.
Issue
with
Troubleshooting
The reason for doFuture missing
ind
as a global variable is because theforeach()
call in caret is basically:Note how
ind
is a global variable whenbag == FALSE
whereas a local variable whenbag == TRUE
. A type of ambiguity that is allowed in R.Given that the foreach expression may be evaluated anywhere (=exported), I'd argue that the proper way to write this code would be to use:
However, that won't change the fact that above code may still exist and is expected to work also with doFuture.
Action
This needs to be solved by the globals package; I've created https://github.com/HenrikBengtsson/globals/issues/31 for this.
Now, why didn't the package tests of doFuture pick this up, especially since it runs through the examples of caret? Turns out that
example("avNNet", package = "caret")
is wrapped in\dontrun{}
. I'll update the doFuture tests to also userun.dontrun = TRUE
so this error will be detected./ht @hanase