Re: [Rd] copying promise

From: Thomas Friedrichsmeier <>
Date: Thu, 20 Sep 2007 20:54:17 +0200


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.

Thomas mailing list
Received on Thu 20 Sep 2007 - 18:56:58 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 20 Sep 2007 - 20:42:15 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.