[Rd] as.list() for function:s

Henrik Bengtsson hb at stat.berkeley.edu
Thu Oct 16 21:51:40 CEST 2008


Hi, a quick comment.  I just notice that as.list() deals with
function:s the old way inside the "default" function, cf.

> as.list.default
function (x, ...)
{
    if (typeof(x) == "list")
        return(x)
    if (is.function(x))
        return(c(formals(x), list(body(x))))
    .Internal(as.vector(x, "list"))
}
<environment: namespace:base>

The following should do the same thing cleaner (and faster?):

as.list.function <- function(x, ...)
{
    c(formals(x), list(body(x)))
}

as.list.default <- function (x, ...)
{
    if (typeof(x) == "list")
        return(x)
    .Internal(as.vector(x, "list"))
}

/Henrik



More information about the R-devel mailing list