[Rd] force promises inside lapply

Benjamin Tyner btyner at gmail.com
Sat Jul 29 00:04:30 CEST 2017


Hi,

I thought I understood the change to lapply semantics resulting from this,

    https://bugs.r-project.org/bugzilla/show_bug.cgi?id=16093

However, would someone care to explain why this does not work?

    > L <- list(a=1, b=2, c=3)
    > str(lapply(L, function(x){ y <- substitute(x); force(x); eval(y) }))
    Error in eval(y) : object 'X' not found

Basically, my primary goal is to achieve the same result as,

    > str(lapply(L, function(x){ eval.parent(substitute(x)) }))
    List of 3
     $ a: num 1
     $ b: num 2
     $ c: num 3

but without having to resort to eval.parent as that seems to rely on an 
implementation detail of lapply.

My secondary goal is to understand why force(x) does not actually force 
the promise here,

    > str(lapply(L, function(x){ force(x); pryr::is_promise(x) }))
    List of 3
     $ a: logi TRUE
     $ b: logi TRUE
     $ c: logi TRUE
,
Regards
Ben



More information about the R-devel mailing list