[Rcpp-devel] Checking for a promise

Gabor Grothendieck ggrothendieck at gmail.com
Sat Dec 25 04:39:06 CET 2010

On Fri, Dec 24, 2010 at 8:10 PM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote:
> How do I fix this so it works?  The code is intended to return TRUE or
> FALSE according to whether the variable with name nm in environment
> env is a promise or not.  In the example code below it returns FALSE
> but I would like it to return TRUE.  Is the promise being forced
> somewhere along the way?  Some other problem?
> library(Rcpp)
> f <- cxxfunction(signature(env="environment", nm = "character"),
>        body=' Environment e(env);
>           std::string s = as<std::string>(nm);
>           return wrap(TYPEOF (e[s]) == PROMSXP); ',
>        plugin="Rcpp")
> # create promise
> delayedAssign("prom", 3)
> # want it to return TRUE but it returns FALSE
> f(.GlobalEnv, "prom")

Or perhaps this is closer but it still does not work as intended:

f <- cxxfunction(signature(s="SEXP"),
   body=' return wrap(TYPEOF(s));',

f(f) # 3
# note that promises are type 5 but we get:
delayedAssign("prom", 3)
f(prom) # 14

Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

More information about the Rcpp-devel mailing list