[Rd] copying promise

Thomas Friedrichsmeier thomas.friedrichsmeier at ruhr-uni-bochum.de
Thu Sep 20 20:54:17 CEST 2007


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 
	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 

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part.
Url : https://stat.ethz.ch/pipermail/r-devel/attachments/20070920/bd415005/attachment.bin 

More information about the R-devel mailing list