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

From: Martin Morgan <mtmorgan_at_fhcrc.org>
Date: Fri 07 Jul 2006 - 12:37:32 GMT


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)

More generally, perhaps as.vector might not duplicate when mode(x) == mode ?

Martin

R version 2.4.0 Under development (unstable) (2006-07-05 r38495) x86_64-unknown-linux-gnu

locale:
LC_CTYPE=en_US;LC_NUMERIC=C;LC_TIME=en_US;LC_COLLATE=en_US;LC_MONETARY=en_US;LC_MESSAGES=en_US;LC_PAPER=en_US;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US;LC_IDENTIFICATION=C

attached base packages:
[1] "tools" "methods" "stats" "graphics" "grDevices" "utils"
[7] "datasets" "base"



R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri Jul 07 22:41:39 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 Sat 08 Jul 2006 - 02:25:54 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.