[Rcpp-devel] Checking for a promise

Gabor Grothendieck ggrothendieck at gmail.com
Sat Dec 25 22:08:37 CET 2010


On Sat, Dec 25, 2010 at 3:58 PM, Dominick Samperi <djsamperi at gmail.com> wrote:
> 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).
>

Note that the first attempt I posted tried to get around that by
passing the environment and the name of the variable in the
environment so that the object would not itself be passed yet it did
not work either.  Here is a slight variation:

> library(Rcpp)
> library(inline)
> f <- cxxfunction(signature(env="environment", nm = "character"),
+        body=' Environment e(env);
+           std::string s = as<std::string>(nm);
+           return wrap(TYPEOF (e[s])); ',
+        plugin="Rcpp")
>
> # create promise
> delayedAssign("prom", 3)
>
> # want it to return 5 but it returns 14
> f(.GlobalEnv, "prom")
[1] 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