Message-ID: <77EB52C6DD32BA4D87471DCD70C8D700021ECBBC@NA-PA-VBE03.na.tibco.com>
Date: 2009-11-09T21:38:26Z
From: William Dunlap
Subject: Negative integer subscripts in [[?
Should negative subscripts be outlawed in
x[[subscript]]
?
Currently, if subscript is a scalar then it can only
be negative if length(x)==1 (otherwise [[ throws an
error). If length(subscript)>1 then it gets treated
as an attempt to recursively extract an element of
a nested list.
> list(10,20)[[-1]] # get the last element out of 2
[1] 20
> list(10,20,30)[[-(1:2)]] # get the last of 3? No.
Error in list(10, 20, 30)[[-(1:2)]] :
attempt to select more than one element
> list(10,list(20,30))[[-c(1:2)]] # see how recursive subscripting is
done
[1] 20
If negative subscripts were not allowed in [[ then
there might be a little less confusion about [[.
(If recursive subscripting were done by a list instead
of by an integer or character vector there might be
less confusion and it would be more flexible.)
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com