# [Rd] Re: removing elements that aren't there -- options(check.bounds)

**Martin Maechler
**
Martin Maechler <maechler@stat.math.ethz.ch>

*Wed, 15 Nov 2000 08:30:29 +0100*

>>>>>* "TL" == Thomas Lumley <thomas@biostat.washington.edu> writes:
*(to R-core, but MM thinks R-devel'ers might want to contribute ..)
TL> Now we have option$check.bounds
{in R 1.2 (unstable) aka "R-devel"}
TL> could we consider allowing negative
TL> subscripts outside the array bounds:
TL> x <- 1:3
TL> x[-4]
TL> is an error in R but not in S.
TL> I think there is a much stronger case for x[-4] to succeed than for
TL> x[4], which we do allow.
I tend to agree.
Note that currently, options(check.bounds = TRUE)
only affects `sub-assignment', i.e. the "[<-" functions,
and not `sub-setting' (aka "[") :
> options(check.bounds = TRUE)
> x[4]
[1] NA
> x[-4]
Error: subscript out of bounds
> x[4] <- 4
Warning message:
assignment outside vector/list limits (extending from 3 to 4)
> x[-5]
Error: subscript out of bounds
> x[5]
[1] NA
I tend to think that options(check.bounds = TRUE)
should
- also warn when `subsetting' outside given bounds
- only warn in the above x[-4] case
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._