Dear R devel,

as.list() can be used on functions, but not if they have a S3 class that
doesn't include "function".

See below :

```r
add1 <- function(x) x+1

as.list(add1)
#> $x
#>
#>
#> [[2]]
#> x + 1

class(add1) <- c("function", "foo")

as.list(add1)
#> $x
#>
#>
#> [[2]]
#> x + 1

class(add1) <- "foo"

as.list(add1)
#> Error in as.vector(x, "list"): cannot coerce type 'closure' to vector of
type 'list'

as.list.function(add1)
#> $x
#>
#>
#> [[2]]
#> x + 1
```

In failing case the argument is dispatched to as.list.default instead of
as.list.function.

(1) Shouldn't it be dispatched to as.list.function ?

(2) Shouldn't all generics when applied on an object of type closure fall
back to the `fun.function` method  before falling back to the `fun.default`
method ?

Best regards,

Antoine

        [[alternative HTML version deleted]]

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to