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

2006-07-11 Thread Thomas Lumley
On Tue, 11 Jul 2006, Martin Morgan wrote: > This is because RObjToCPtr is not quite careful enough with NAMED, > rather than an issue with as.XXX But DUP=FALSE is documented to be dangerous for this very reason. It never copies, and ?.C makes it clear that .C(,DUP=FALSE) can modify variables th

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

2006-07-11 Thread Martin Morgan
This is because RObjToCPtr is not quite careful enough with NAMED, rather than an issue with as.XXX tmp.c: void tmp(double *x) { x[0]=1; return; } > f <- function(x) x > x <- 0 > .C("tmp", f(x), DUP=FALSE) [[1]] [1] 1 > x [1] 1 > x <- 0 > y <- x > .C("tmp", x, DUP=FALSE) [[1]] [1] 1 > y [1] 1

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

2006-07-11 Thread Prof Brian Ripley
On Tue, 11 Jul 2006, Prof Brian Ripley wrote: > On Fri, 7 Jul 2006, Thomas Lumley wrote: > > On Fri, 7 Jul 2006, Martin Morgan wrote: [...] > > > More generally, perhaps as.vector might not duplicate when mode(x) == > > > mode ? > > > > This isn't a trivial change, because mode(x)==mode does

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

2006-07-11 Thread Prof Brian Ripley
On Tue, 11 Jul 2006, Thomas Lumley wrote: > On Tue, 11 Jul 2006, Prof Brian Ripley wrote: > > > On Fri, 7 Jul 2006, Thomas Lumley wrote: > > > > > On Fri, 7 Jul 2006, Martin Morgan wrote: > > > > > > > sapply calls lapply as > > > > > > > >answer <- lapply(as.list(X), FUN, ...) > > > > > > >

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

2006-07-11 Thread Thomas Lumley
On Tue, 11 Jul 2006, Prof Brian Ripley wrote: > On Fri, 7 Jul 2006, Thomas Lumley wrote: > >> 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 >>> c

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

2006-07-11 Thread Prof Brian Ripley
On Fri, 7 Jul 2006, Thomas Lumley wrote: > 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

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

2006-07-07 Thread Thomas Lumley
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) T

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

2006-07-07 Thread Martin Morgan
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