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

From: Martin Maechler <maechler_at_stat.math.ethz.ch>
Date: Fri, 17 Oct 2008 11:27:51 +0200

>>>>> "HenrikB" == Henrik Bengtsson <hb_at_stat.berkeley.edu>
>>>>> on Thu, 16 Oct 2008 12:51:40 -0700 writes:

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

    >> as.list.default

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

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

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

    HenrikB> as.list.default <- function (x, ...)
    HenrikB> {
    HenrikB> if (typeof(x) == "list")
    HenrikB> return(x)

    HenrikB> .Internal(as.vector(x, "list"))     HenrikB> }

I don't think it will be faster, but definitely cleaner. I've implemented (a version of) it for R-devel.

Martin



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Fri 17 Oct 2008 - 09:30:00 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Fri 17 Oct 2008 - 15:30:22 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.

list of date sections of archive