From Kurt.Hornik@ci.tuwien.ac.at  Thu Apr 12 11:58:45 2001
From: Kurt.Hornik@ci.tuwien.ac.at (Kurt Hornik)
Date: Thu, 12 Apr 2001 12:58:45 +0200
Subject: [Rd] replicating lists
In-Reply-To: <Pine.GSO.4.31.0104120925470.823-100000@toucan.stats>
References: <Pine.GSO.4.20.0104120859570.13680-100000@laplace>
 <Pine.GSO.4.31.0104120925470.823-100000@toucan.stats>
Message-ID: <15061.35429.294081.705880@mithrandir.hornik.net>

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

We had a similar discussion when fixing all.equal problems with lists.
These are generic vectors and not hashtables, hence I think the above is
the ``right approach'' (following the general principle).

-k
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] replicating lists
Kurt Hornik