From wdunlap at tibco.com  Mon Feb  7 20:56:14 2011
From: wdunlap at tibco.com (William Dunlap)
Date: Mon, 7 Feb 2011 11:56:14 -0800
Subject: [Rd] as.list(subclassed function) -> cannot coerce type 'closure'
	to vector of type 'list'
Message-ID: <77EB52C6DD32BA4D87471DCD70C8D70003DE1FB8@NA-PA-VBE03.na.tibco.com>

I was looking for all the glm-related 'family' functions
in stats using the following predicate that returns TRUE
for any function whose first argument is called "link".
   is.family <- function(object) is.function(object) &&
            identical(names(as.list(object))[1], "link")

It threw an error when applied to SSfol
   > is.family(SSfol)
   Error in as.vector(x, "list") :
     cannot coerce type 'closure' to vector of type 'list'
but works when I unclass SSfol
   > is.family(unclass(SSfol))
   [1] FALSE

It looks like as.list fails on any function that is assigned
a class:
   > as.list(function(x)x+1)
   $x
   
   
   [[2]]
   x + 1

   > as.list(structure(function(x)x+1, class="unrecognized class name"))
   Error in as.vector(x, "list") :
     cannot coerce type 'closure' to vector of type 'list'

Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com 



[Rd] as.list(subclassed function) -> cannot coerce type 'closure' to vector of type 'list'
William Dunlap