[Rcpp-devel] Checking for a promise

Dominick Samperi djsamperi at gmail.com
Sat Dec 25 21:58:41 CET 2010


Using .Call appears to force the promise:

msg="old"
delayedAssign("x",msg)
msg="new"
.Call('sexpType',x) # promise triggered here, returns 16
msg="even newer" # will not change already fired promise
.Call('sexpType',x) # returns 16
y = x
y # "new" (not "even newer")

Here's sexpType:

RcppExport SEXP sexpType(SEXP x_) {
    return Rcpp::wrap(TYPEOF(x_));
}

The type returned is 16 here (STRSXP). If numbers were
assigned to msg instead 14 would be returned (REALSXP).

On Fri, Dec 24, 2010 at 10:39 PM, Gabor Grothendieck <
ggrothendieck at gmail.com> wrote:

> 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:
>
> library(Rcpp)
> library(inline)
> f <- cxxfunction(signature(s="SEXP"),
>   body=' return wrap(TYPEOF(s));',
>   plugin="Rcpp")
>
> 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
> _______________________________________________
> Rcpp-devel mailing list
> Rcpp-devel at lists.r-forge.r-project.org
> https://lists.r-forge.r-project.org/cgi-bin/mailman/listinfo/rcpp-devel
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.r-forge.r-project.org/pipermail/rcpp-devel/attachments/20101225/2ad78f57/attachment.htm>


More information about the Rcpp-devel mailing list