HenrikBengtsson / future.tests

:nut_and_bolt: R package: future.tests - Test Suite for Future API Backends
https://future.tests.futureverse.org
10 stars 1 forks source link

TEST: rm() must not remove globals #19

Closed HenrikBengtsson closed 1 year ago

HenrikBengtsson commented 2 years ago
a <- 42
f <- future({
  a <- 3.14
  rm(a)
  a
})

should return 42.

HenrikBengtsson commented 2 years ago
library(future)
plan(sequential)
a <- 42
f <- future({
  a
  a <- 3.14
  rm(a)
  a
})
value(f)
#> [1] 42

but that's a lucky side effect, because:

a <- 42
f <- future({
  a
  a <- 3.14
  rm(a)
  a
}, lazy = TRUE)
rm(a)
value(f)
#> Error in eval(quote({ : object 'a' not found

and

library(future)
plan(cluster, workers = 1L)
a <- 42
f <- future({
  a
  a <- 3.14
  rm(a)
  a
})
value(f)
#> Error in withCallingHandlers({ : object 'a' not found