[Rd] [[ vs. .subset2

Peter Dalgaard p.dalgaard at biostat.ku.dk
Sat Jul 5 14:04:33 CEST 2008


Gabor Grothendieck wrote:
> Not really.  The point of this is that promises seem to be
> screwing up in conjunction with [[ but in light of the fact
> that .subset2 works it suggests that there might be a better
> implementation of [[
Not really; .subset2() is a shortcut that bypasses method dispatch, so 
not a drop-in replacement for "[[". You also have

 > test3 <- function(pf = parent.frame()) "[[.data.frame"(BOD, pf$idx)
 > test3()
[1]  8.3 10.3 19.0 16.0 15.6 19.8


Something appears not quite right, but an easy workaround is to force 
the promise:

 > test4 <- function(pf = parent.frame()) {pf;BOD[[pf$idx]]}
 > test4()
[1]  8.3 10.3 19.0 16.0 15.6 19.8



-- 
   O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907



More information about the R-devel mailing list