MangoTheCat/cyclocomp

Bug for using `next` within `foreach::foreach`

Closed this issue · 3 comments

E.g.

f <- function () {
  foreach(k = 1:10) %dopar% { next }
}
cyclocomp::cyclocomp(f)
#> Error in edges$from[num_edges + (1:n)] <<- head(args, -1) :
#>   replacement has length zero

Seems like this is actually invalid code and you cannot use next without a loop. Syntactically it is OK, but it just does not work.

For your particular example, I think the foreach code in ecospat.ESM.Projection is broken. You need to use return() instead of next in the parallel version of the code. See e.g. http://stackoverflow.com/a/15368988/604364

Nevertheless cyclocomp (and thus goodpractice) now does not fail on it.

Thanks a lot for the feedback, I will test it now. Cheers