From btyner at gmail.com  Sat Jul 29 00:04:30 2017
From: btyner at gmail.com (Benjamin Tyner)
Date: Fri, 28 Jul 2017 18:04:30 -0400
Subject: [Rd] force promises inside lapply
Message-ID: <a08cf018-5c19-fe67-9ee8-6d0e403b9cfa@gmail.com>

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



[Rd] force promises inside lapply
Benjamin Tyner