Re: [Rd] often unnecessary duplicate in sapply / as.vector

From: Prof Brian Ripley <>
Date: Tue 11 Jul 2006 - 19:32:38 GMT

On Tue, 11 Jul 2006, Prof Brian Ripley wrote:

> On Fri, 7 Jul 2006, Thomas Lumley wrote:

> > On Fri, 7 Jul 2006, Martin Morgan wrote:


> > > More generally, perhaps as.vector might not duplicate when mode(x) == mode ?
> >
> > This isn't a trivial change, because mode(x)==mode does not guarantee
> > that as.vector(x, mode) has no effect. For example, with mode="numeric" it
> > removes attributes.
> And with mode="list" it does not (although that is not as documented).
> We can certainly do better. [This is another of those cases where 'mode'
> is confusing, and in fact it would be typeof(x) == mode.]

Aargh: of course I should have guessed that quite a few people have written code that assumes that e.g. as.double() duplicates. The first I came across is a .Fortran call in smooth.spline with DUP=FALSE which despite all the warnings changes its 'w' argument and hence the return result from smooth.spline if as.double is made more efficient.

I really have no desire to spend any more time tracking down problems caused by such rogue code, so I am going to leave this as is (with as.list somewhat more efficient but the as.vector functions always duplicating).

Brian D. Ripley,        
Professor of Applied Statistics,
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________ mailing list
Received on Wed Jul 12 05:37:27 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 11 Jul 2006 - 22:28:33 GMT.

Mailing list information is available at Please read the posting guide before posting to the list.