# Re: R-alpha: Misc problems

Ross Ihaka (ihaka@stat.auckland.ac.nz)
Tue, 18 Feb 1997 08:41:49 +1300 (NZDT)

```Date: Tue, 18 Feb 1997 08:41:49 +1300 (NZDT)
From: Ross Ihaka <ihaka@stat.auckland.ac.nz>
Message-Id: <199702171941.IAA15735@stat1.stat.auckland.ac.nz>
To: jlindsey@luc.ac.be, maechler@stat.math.ethz.ch
Subject: Re: R-alpha: Misc problems

Martin Maechler stands accused of saying:

> >>>>> "Jim" == Jim Lindsey <jlindsey@luc.ac.be> writes:

>     Jim> 1. The S books often give examples using something like this:
>     Jim>   u <- list()
>     Jim>   u[[1]] <- a

>     Jim> In R this gives subscript out of bounds (also character, vector, etc.)

> I think that R is okay here;
> Why using unnamed lists anyway?
> In the above example, you can do

> 	u \$ a.name  <-  a

> A similar issue (which was discussed on this list a while ago):

> 	x    <- 1:4
> 	x[6] <- 6

> works in S, but not in R.
> The decision was that R should help you to detect programming errors.

Yes this was the rationale,  but we also took a board decision to be as
compatible as possible with S (the year before last no?).

provides "stretchy" vectors and lists for the next version.  There is a
lot of code which uses this facility.  I have been checking our object
system code by running Bill Venables "polynomial" class code and it
uses this facility.

I might point out that this tends to be very inefficient, on a par
with:
x <- NULL
for(i in 1:10) x <- c(x, i)

which is better written as
x <- numeric(10)
for(i in 1:10) x[i] <- i

You might also want to amuse yourself by trying the following code in S:
x <- matrix(1:10, nc=2)
x
x[20] <- 17
x
# Hunh? where did the extra values go?
c(x)
# Oh! there they are

Ross
~v
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-testers mailing list -- For info or help, send "info" or "help",
To [un]subscribe, send "[un]subscribe"
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
```