|
4 | 4 |
|
5 | 5 | library(doFuture) |
6 | 6 | options( |
7 | | - parallelly.debug = TRUE, |
8 | | - future.debug = TRUE, |
9 | | - doFuture.debug = TRUE |
| 7 | +# parallelly.debug = TRUE, |
| 8 | +# future.debug = TRUE, |
| 9 | +# doFuture.debug = TRUE |
10 | 10 | ) |
11 | 11 |
|
12 | 12 | strategies <- future:::supportedStrategies() |
@@ -129,6 +129,50 @@ for (strategy in strategies) { |
129 | 129 | str(z1) |
130 | 130 | stopifnot(identical(z1, z0)) |
131 | 131 |
|
| 132 | + message("- foreach() - globals are picked up ...") |
| 133 | + y <- foreach(x = 0) %dofuture% { |
| 134 | + message(sprintf("Globals: a = %s, b = %s", a, b)) |
| 135 | + y ~ a + b |
| 136 | + } |
| 137 | + stopifnot(is.list(y), length(y) == 1L, inherits(y[[1]], "formula")) |
| 138 | + |
| 139 | + message("- foreach() - .export and .noexport must not be used ...") |
| 140 | + y <- tryCatch({ |
| 141 | + foreach(x = 0, .export = c("a", "b")) %dofuture% { |
| 142 | + message(sprintf("Globals: a = %s, b = %s", a, b)) |
| 143 | + y ~ a + b |
| 144 | + } |
| 145 | + }, error = identity) |
| 146 | + stopifnot(inherits(y, "error")) |
| 147 | + |
| 148 | + y <- tryCatch({ |
| 149 | + foreach(x = 0, .noexport = c("a", "b")) %dofuture% { |
| 150 | + message(sprintf("Globals: a = %s, b = %s", a, b)) |
| 151 | + y ~ a + b |
| 152 | + } |
| 153 | + }, error = identity) |
| 154 | + stopifnot(inherits(y, "error")) |
| 155 | + |
| 156 | + message("- foreach() - globals can be added ...") |
| 157 | + y <- tryCatch({ |
| 158 | + foreach(x = 0, .options.future = list(globals = structure(TRUE, add = c("a", "b")))) %dofuture% { |
| 159 | + message(sprintf("Globals: a = %s, b = %s", get("a"), get("b"))) |
| 160 | + y ~ 42 |
| 161 | + } |
| 162 | + }, error = identity) |
| 163 | + stopifnot(is.list(y), length(y) == 1L, inherits(y[[1]], "formula")) |
| 164 | + |
| 165 | + message("- foreach() - globals can be ignored ...") |
| 166 | + y <- tryCatch({ |
| 167 | + foreach(x = 0, .options.future = list(globals = structure(TRUE, ignore = c("a", "b")))) %dofuture% { |
| 168 | + message(sprintf("Globals: a = %s, b = %s", a, b)) |
| 169 | + y ~ a + b |
| 170 | + } |
| 171 | + }, error = identity) |
| 172 | + stopifnot( |
| 173 | + inherits(y, "error") || inherits(plan("next"), c("sequential", "multicore")) |
| 174 | + ) |
| 175 | + |
132 | 176 | # Shutdown current plan |
133 | 177 | plan(sequential) |
134 | 178 | } ## for (strategy ...) |
|
0 commit comments