From vincent.goulet at act.ulaval.ca  Fri May  2 22:11:04 2008
From: vincent.goulet at act.ulaval.ca (Vincent Goulet)
Date: Fri, 2 May 2008 16:11:04 -0400
Subject: [Rd] Out of bounds negative index
In-Reply-To: <481B6F9E.7080201@stats.uwo.ca>
References: <DFD3645F-329A-4280-A256-4708B0D54503@act.ulaval.ca>
	<481B6F9E.7080201@stats.uwo.ca>
Message-ID: <384B9416-5FC9-45AC-AB0A-B8E8D1268F8F@act.ulaval.ca>

Le ven. 02 mai ? 15:46, Duncan Murdoch a ?crit :

> On 5/2/2008 3:23 PM, Vincent Goulet wrote:
>> Hi,
>> From the R Language Definition, Section 3.4.1:
>> "If i is positive and exceeds length(x) then the corresponding   
>> selection is NA. A negative out of bounds value for i causes an  
>> error."
>> (This is also mentioned in S Programming, footnote of page 24.)
>> Can someone please provide an example triggering the error? Looking  
>> in  src/main/subscript.c I could not find exception handling for | 
>> i| >  length(x), unless the negative subscript is mixed with NAs.  
>> In other  cases, out of bounds negative indexes just seem silently  
>> ignored.
>> Did I missed or misinterpreted something, here?
>
> Looks to me like a documentation error.  I would expect from that  
> description that executing
>
> > x <- 1:5
> > x[7]
> [1] NA
> > x[-7]
> [1] 1 2 3 4 5
>
> would have given an error on x[-7], but clearly it didn't.  This  
> behaviour appears to have started with 2.6.0; 2.5.1 gives the  
> error.  I don't see a NEWS entry about it...but revision r42123 says
>
> Changed the behaviour of out-of-bounds negative
> subscripts to match that of S.  Such values are
> now ignored rather than tripping an error.

Ah ha, there it is. The svn log is one place I didn't look. I had  
screened NEWS, ONEWS and OONEWS, though...

Thanks, Duncan.

>
>
> so apparently it was intentional.
>
> Duncan Murdoch



[Rd] Out of bounds negative index
Vincent Goulet