DavisVaughan/furrr

future_map with .f = ~ eval(parse(text = .))

Closed this issue · 3 comments

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)

This is pretty much the same as #207

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

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)