From murdoch at stats.uwo.ca  Fri May  2 21:50:29 2008
From: murdoch at stats.uwo.ca (Duncan Murdoch)
Date: Fri, 02 May 2008 15:50:29 -0400
Subject: [Rd] Out of bounds negative index
In-Reply-To: <f8e6ff050805021229l2c1b36c9kdf0ee276849646db@mail.gmail.com>
References: <DFD3645F-329A-4280-A256-4708B0D54503@act.ulaval.ca>
	<f8e6ff050805021229l2c1b36c9kdf0ee276849646db@mail.gmail.com>
Message-ID: <481B7085.2030708@stats.uwo.ca>

On 5/2/2008 3:29 PM, hadley wickham wrote:
> On Fri, May 2, 2008 at 2:23 PM, Vincent Goulet
> <vincent.goulet at act.ulaval.ca> 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?
> 
> Well, there's this:
> 
>> a <- 1:10
>> a[NA]
>  [1] NA NA NA NA NA NA NA NA NA NA
>> a[-NA]
> [1] NA

But NA and -NA are different:  the first is logical, the latter is an 
integer.

Duncan Murdoch



[Rd] Out of bounds negative index
Duncan Murdoch