From spluque at gmail.com  Tue Sep 14 00:11:41 2010
From: spluque at gmail.com (Seb)
Date: Mon, 13 Sep 2010 17:11:41 -0500
Subject: [Rd] value returned by by()
Message-ID: <87vd69b8f6.fsf@kolob.sebmags.homelinux.org>

Hi,

I noticed that by() returns an object of class 'by', regardless of what
its argument 'simplify' is.  ?by says that it always returns a list if
simplify=FALSE, yet by.data.frame shows:

---<--------------------cut here---------------start------------------->---
function (data, INDICES, FUN, ..., simplify = TRUE) 
{
    if (!is.list(INDICES)) {
        IND <- vector("list", 1L)
        IND[[1L]] <- INDICES
        names(IND) <- deparse(substitute(INDICES))[1L]
    }
    else IND <- INDICES
    FUNx <- function(x) FUN(data[x, , drop = FALSE], ...)
    nd <- nrow(data)
    ans <- eval(substitute(tapply(1L:nd, IND, FUNx, simplify = simplify)), 
        data)
    attr(ans, "call") <- match.call()
    class(ans) <- "by"
    ans
}
<environment: namespace:base>
---<--------------------cut here---------------end--------------------->---

One could force a list by wrapping it around an lapply(by.object, "["),
but this is not possible if the object contains S4 objects.  How does
one force a list in those cases?


Cheers,

-- 
Seb



[Rd] value returned by by()
Seb