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

Thomas Lumley tlumley at u.washington.edu
Sat Jul 8 02:04:40 CEST 2006


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



More information about the R-devel mailing list