From mtmorgan at fhcrc.org  Fri Jul  7 14:37:32 2006
From: mtmorgan at fhcrc.org (Martin Morgan)
Date: Fri, 07 Jul 2006 05:37:32 -0700
Subject: [Rd] often unnecessary duplicate in sapply / as.vector
Message-ID: <6phlkr5lhf7.fsf@gopher1.fhcrc.org>

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"



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