future_map with .f = ~ eval(parse(text = .))
Closed this issue · 3 comments
abdellah19jan commented
In the code below the map function works fine while the future_map function doesn't work:
library(furrr)
library(tidyverse)
plan(multisession)
x <- 0
y <- parse(text = "x")
map(y, eval)
future_map(y, eval)
DavisVaughan commented
This is pretty much the same as #207
DavisVaughan commented
Oh actually this might be a globals bug, sorry.
y_expressions <- parse(text = "x")
y_symbol <- quote(x)
globals::findGlobals(y_expressions)
#> character(0)
globals::findGlobals(y_symbol)
#> [1] "x"
Created on 2021-10-25 by the reprex package (v2.0.1)
I'll report it over there and see what Henrik says
DavisVaughan commented
Simple solution in the meantime is to explicitly convert the "expressions"
class to a list with as.list()
. It should all work the same
library(furrr)
#> Loading required package: future
plan(multisession, workers = 2)
x <- 0
y <- parse(text = "x")
# This is basically a list of expressions
y
#> expression(x)
as.list(y)
#> [[1]]
#> x
future_map(y, eval)
#> Error in ...furrr_fn(...): object 'x' not found
future_map(as.list(y), eval)
#> [[1]]
#> [1] 0
Created on 2021-10-25 by the reprex package (v2.0.1)