[Rd] Negative integer subscripts in [[?

From: William Dunlap <wdunlap_at_tibco.com>
Date: Mon, 09 Nov 2009 13:38:26 -0800

Should negative subscripts be outlawed in


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
[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

R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Mon 09 Nov 2009 - 21:40:09 GMT

This archive was generated by hypermail 2.2.0 : Tue 10 Nov 2009 - 02:00:23 GMT