[Rd] delay() has been deprecated for 2.1.0

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Fri 11 Mar 2005 - 16:05:48 GMT

After a bunch of discussion in the core group, we have decided to deprecate the delay() function (which was introduced as "experimental" in R 0.50). This is the function that duplicates in R code the delayed evaluation mechanism (the promise) that's used in evaluating function arguments.

The problem with delay() was that it was handled inconsistently (e.g. sometimes you would see an object displayed as <promise:...>, sometimes it would be evaluated); it tended to be error-prone in usage
(e.g. this was the cause of the bug that makes the curve() function
create a "pu" object in the global environment); and it was generally difficult to figure out exactly what the semantics of it should be in order to be consistent.

delay() has been replaced with delayedAssign(). This new function creates a promise and assigns it into an environment. Once one more set of changes is made and delay() is gone, there should be no way to see a <promise: ...> object in R: as soon as the object is accessed, it will be evaluated and you'll see the value.

A few packages made use of delay(). I have replaced all of those uses with delayedAssign(). The most common usage was something like the QA code uses:

assign("T", delay(stop("T used instead of TRUE")),

                  pos = .CheckExEnv)

This translates to

delayedAssign("T", stop("T used instead of TRUE"), eval.env = .GlobalEnv, assign.env = .CheckExEnv)

In most cases the "eval.env = .GlobalEnv" argument is not necessary
(and in fact it is often a bug, as it was in curve()). The
environment where the promise is to be evaluated now defaults to the environment where the call is being made, rather than the global environment, and this is usually what you want.

Package writers who use delay() will now get a warning that it has been deprecated. They should recode their package to use delayedAssign instead.

Examples from CRAN of this (I am not sure if this list is exhaustive):

exactRankTests, genetics, g.data, maxstat, taskPR, coin

I have cc'd the maintainers of those packages.

If you want a single code base for your package that works in both the upcoming R 2.1.0 and older versions, this presents a problem: older versions don't have delayedAssign. Here is a workalike function that could be used in older versions:

delayedAssign <- function(x, value,

		eval.env = parent.frame(),
		assign.env = parent.frame()) {
 assign(x, .Internal(delay(substitute(value), eval.env)), 
           envir = assign.env)


Because this function calls the internal delay() function directly, it should work in R 2.1.0+ as well without a warning, but the internal function will eventually go away too, so I don't recommend using it in the long term.

Sorry for any inconvenience that this causes.

Duncan Murdoch

R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon Mar 14 10:34:07 2005

This archive was generated by hypermail 2.1.8 : Mon 20 Feb 2006 - 03:21:01 GMT