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

From: Thomas Lumley <tlumley_at_u.washington.edu>
Date: Sat 08 Jul 2006 - 00:04:40 GMT

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@u.washington.edu	University of Washington, Seattle

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Sat Jul 08 10:07:46 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 - 14:30:23 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.