From tlumley at u.washington.edu  Sat Jul  8 02:04:40 2006
From: tlumley at u.washington.edu (Thomas Lumley)
Date: Fri, 7 Jul 2006 17:04:40 -0700 (PDT)
Subject: [Rd] often unnecessary duplicate in sapply / as.vector
In-Reply-To: <6phlkr5lhf7.fsf@gopher1.fhcrc.org>
References: <6phlkr5lhf7.fsf@gopher1.fhcrc.org>
Message-ID: <Pine.LNX.4.64.0607071652450.9075@homer23.u.washington.edu>

On Fri, 7 Jul 2006, Martin Morgan wrote:

> sapply calls lapply as
>
>    answer <- lapply(as.list(X), FUN, ...)
>
> which, when X is a list, causes X to be duplicated unnecessarily. The
> coercion is unnecessary for other mode(X) because in lapply we have
>
>    if (!is.list(X)) X <- as.list(X)

That looks reasonable.

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


         -thomas

Thomas Lumley			Assoc. Professor, Biostatistics
tlumley at u.washington.edu	University of Washington, Seattle



[Rd] often unnecessary duplicate in sapply / as.vector
Thomas Lumley