[Rd] bound checking (for "x[] <-") now in R-devel

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Fri, 3 Nov 2000 17:48:16 +0100


I'm following a `discussion on R-help'
>>>>> "MM" == Martin Maechler <maechler@stat.math.ethz.ch> writes:

>>>>> "Peter" == Peter Perkins <pperkins@ucsd.edu> writes:
    >>> AUcap30<-0 
    >>> for(i in 1:length(AU)) AUcap30[i] <- min(30,AU[i])

    Peter> am i right in thinking that this is an implicit version of

    Peter> for(i in 1:length(AU)) AUcap30 <- c(AUcap30, min(30,AU[i])) ?

    MM> yes (as others have said on this thread).

    Peter> huh.  i guess i'm surprised that this even works at all.  i
    Peter> don't see any specific mention in section 3 of the FAQ, and a
    Peter> quick look at the R intro documents turned up no mention either.

    MM> (really, I thought it *was* there;  no time to search now..)

    Peter> but i seem to remember that it would not work in S (not that
    Peter> that is necessarily a reason for it not to work in R).

    MM> yes, it has been working in S `since ever' (even before there was S+).

    Peter> i kind of _like_ having array bounds checking -- is "array
    Peter> extension on out of bounds indexing" really the default in R,

    MM> yes (and will be)

    Peter> and is there a way to enforce array bounds checking?

    MM> not currently, but probably, there will be, by

    MM>        options(check.bound = TRUE)

    MM> which is (only partly implemented) in the current development
    MM> version.

Okay.
In today's development version of R 
(use rsync or tomorrow's or Sunday's snapshot R-devel.tar.gz),
there's now in help(options)

 check.bounds: logical, defaulting to `FALSE'.  If true, a warning is
	   produced whenever a ``generalized vector'' (atomic or `list')
	   is extended, by something like `x <- 1:3; x[5] <- 6'.

and here's an example :

    > x <- 1:3 ; x[5] <- 6
				# no warning

    > options(check.bounds = TRUE)
    > x <- 1:3 ; x[5] <- 6
    Warning message: 
    assignment outside vector/list limits (extending from 3 to 5) 
    >


Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO D10	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._