Prof Brian Ripley writes:
On Thu, 12 Apr 2001, Jonathan Rougier wrote:
Hi Brian,
After a discussion with David James can you clarify exactly what you think
the behaviour of "rep" will be? The three alternatives for rep(fred, 5)
would appear to be
fred <- list(happy = 1:10, name = "squash")
list(fred)[rep(1, 5)] # version 1
fred[rep(seq(along=fred), length=5)] # version 2
unlist(list(fred)[rep(1, 5)], recursive=FALSE) # version 3
I was expecting the first, as this makes sense in the context of
tmp <- array(fred, c(3, 4))
but I can see that the second is also a natural way to think about
replicating a list. I also notice that S+ uses version 3. Personally I
don't like version 3 as it is going to duplicate names, and it is not
going to fit with "array".
Confused, Jonathan.
We follow the prototype in cases of doubt, so version 3. *However*,
S-PLUS does different things by version, so version 6.0 drops the
duplicated names. I really think only 3 makes sense: a list is a
generic vector, and you do exactly the same thing as for any other
sort of vector. The only issue is the names, and
x <- letters[1:3]
names(x) <- x
rep(x, 5)
drops names in S+6.0, keeps them in S+3.4 and R. So the S-PLUS
versions are doing consistent things with character vectors and lists.