[Rd] [[ vs. .subset2

Gabor Grothendieck ggrothendieck at gmail.com
Sat Jul 5 02:12:24 CEST 2008


In the code below test2() gives an error message:

   Error in .subset2(x, i, exact = exact) :
     attempt to select less than one element

even though test(), which is nearly the same, gives
the expected result.  BOD is a data set that comes
with R.   Is this a bug?


idx <- 2

# returns expected result
test <- function(pf = parent.frame()) .subset2(BOD, pf$idx)
test()

# gives error message !!!
test2 <- function(pf = parent.frame()) BOD[[pf$idx]]
test2()


I tried this on Windows Vista under:

> R.version.string
[1] "R version 2.7.1 RC (2008-06-16 r45949)"

and

> R.version.string
[1] "R version 2.8.0 Under development (unstable) (2008-06-28 r46012)"



More information about the R-devel mailing list