R-beta: Re: S Compatibility

Bill Venables wvenable at attunga.stats.adelaide.edu.au
Wed Apr 30 01:51:07 CEST 1997


Thomas Lumley writes:
 > On Wed, 30 Apr 1997, Ross Ihaka wrote:
 > > 
 > > Some things we almost certainly won't be changing.  Scoping
 > > is one of these (although I have to confess that I have made
 > > the pitch to Robert that we should drop our scoping in
 > > favour of the S version - he sensibly said "no").
 > 
 > Quite right too.  My favorite example is a function that I and
 > several of my fellow students have at various times tried to
 > write in S.
 > 
 > jack.lm<-function(lm.obj){
 > 	ii<-as.matrix(1:length(lm.obj$residuals))
 > 	var(t(apply(ii,1,function(i) update(lm.obj,subset=-i)$coef)))
 > 	}
 > 
 > or similar things for bootstrap, weighted bootstrap, glms and
 > so on.  In every case people have spent hours staring at this
 > code and wondering why it claims to be unable to find lm.obj.

Just to satisfy the curious - I'm not saying it is good or bad -
there is a way to do it in S, of course, namely

jack.lm <- function(lm.obj) {
 	ii <- matrix(1:length(lm.obj$residuals))
 	var(t(apply(ii, 1, function(i, obj) 
		update(obj, subset = -i)$coef, lm.obj)))
 	}

My question is, though, will this also work in R?  It it intended
to remain so?  Given that the S scoping rules are more
restrictive, it would be a mistake to make it impossible to write
code that is usable on both systems.

 > My view on the scoping rules of R is that they aren't an
 > incompatibility since most people I have talked to think that
 > S scopes this way.

Are the scoping differences between R and S set out precisely and
definitively somewhere?  This would be useful.

(As a complete side-issue, Brian Ripley and I have a kind of
convention: we refer to the language as "S" and the commercial
product as "S-PLUS".  There is a useful distinction to be made.)
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=



More information about the R-help mailing list