From spencer.graves at pdf.com  Sat Jul  5 02:42:35 2008
From: spencer.graves at pdf.com (Spencer Graves)
Date: Fri, 04 Jul 2008 17:42:35 -0700
Subject: [Rd] [[ vs. .subset2
In-Reply-To: <971536df0807041712x34dafd51xc2ad8dcf0ef30b68@mail.gmail.com>
References: <971536df0807041712x34dafd51xc2ad8dcf0ef30b68@mail.gmail.com>
Message-ID: <486EC37B.9020204@pdf.com>

Dear Gabor: 

      Does the following answer your question: 

 > tst <- list(a=1, b=2)
 > tst[numeric(0)]
list()
 > tst[[numeric(0)]]
Error in tst[[numeric(0)]] : attempt to select less than one element

      Spencer

Gabor Grothendieck wrote:
> 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)"
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>



[Rd] [[ vs. .subset2
Spencer Graves