RE: [Rd] delay() has been deprecated for 2.1.0

From: <Mark.Bravington_at_csiro.au>
Date: Sat 12 Mar 2005 - 00:55:21 GMT


Uh-oh... I've just written a bunch of code for 'mvbutils' using 'delay', and am worried by the statement that "there should be no way to see a <promise:...> object in R". At present, it's possible to check whether 'x' is a promise via e.g. 'class( .GlobalEnv$x)'. This will be different to 'class( x)' if 'x' is a promise, regardless of whether the promise has or has not been forced yet. This can be very useful; my recent code relies on it to check whether certain objects have been changed since last being saved. [These certain objects are originally assigned as promises to load from individual files. Read-accessing the object keeps it as class 'promise', whereas write-access creates a non-promise. Thus I can tell whether the individual files need re-saving when the entire workspace is saved.]  

The has-it-changed test has been very valuable to me in allowing fast handling of large collections of large objects (which is why I've been adding this functionality to 'mvbutils'); and apart from is-it-still-a-promise, I can't think of any other R-level way of testing whether an object has been modified. [If there is another way, please let me know!]  

Is there any chance of retaining *some* R-level way of checking whether an object is a promise, both pre-forcing and post-forcing? (Not necessarily via the 'class( env$x)' method, if that's deemed objectionable.)  

Mark Bravington
mark.bravington@csiro.au  

	-----Original Message----- 
	From: r-devel-bounces@stat.math.ethz.ch on behalf of Duncan Murdoch 
	Sent: Sat 12/03/2005 3:05 AM 
	To: r-devel@stat.math.ethz.ch 
	Cc: Gregory Warnes; David Brahm; Torsten Hothorn; Nagiza F. Samatova 
	Subject: [Rd] delay() has been deprecated for 2.1.0
	
	

	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 ______________________________________________
R-devel@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon Mar 14 10:03:46 2005

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