Hi,

On Thursday 20 September 2007, Gabor Grothendieck wrote:
> 1. Is there some way to copy a promise so that the copy has the same
> expression in its promise as the original.

As far as I am aware (which is not very far at all), there is no way to do 
this in R code. However, it's fairly simple to achieve this in C. For 
example, the following C function is basically the same as

# assign (name, get (name, envir=fromenv), envir=toenv)

except that it does not force any promises:

SEXP doCopyNoEval (SEXP name, SEXP fromenv, SEXP toenv) {
        if(!isString (name) || length (name) != 1) error ("name is not a single 
string");
        if(!isEnvironment (fromenv)) error ("fromenv is not an environment");
        if(!isEnvironment (toenv)) error ("toenv is not an environment");
        defineVar (Rf_install (CHAR (STRING_ELT (name, 0))), findVar 
(Rf_install 
(CHAR (STRING_ELT (name, 0))), fromenv), toenv);
        return (R_NilValue);
}

> 2. Is there some way to determine if a variable holds a promise
> without evaluating it?

Similarly, in C, determining whether an object is a promise is as easy as
# if (TYPEOF (object) == PROMSXP) {}

We use both in RKWard to peek at objects while making sure not to force any 
promises.

Regards
Thomas

Attachment: signature.asc
Description: This is a digitally signed message part.

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to