You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This is just an idea, if it won't get implemented I won't be disappointed.
The idea is that S7 provides methods for S7 objects for the coersion generics in base R.
They can use convert() with prepopulated to arguments.
library(S7)
as.list.S7_object<-function(x) convert(x, class_list)
as.character.S7_object<-function(x) convert(x, class_character)
# also as.numeric, as.factor, etc.
That way, you get this coersion 'for free' if you implement convert() methods.
foo<- new_class("foo")
method(convert, list(foo, class_list)) <-function(from, to) list("foo")
# Works out of the box
as.list(foo())
#> [[1]]#> [1] "foo"# convert is not defined for 'foo'
as.character(foo())
#> Error: Can't find method for generic `convert()` with dispatch classes:#> - from: <foo>#> - to : <character>
Activity
hadley commentedon May 22, 2026
I think Michael's argument in #472 is compelling; S7 builds on top of S3, so
convert()should be defined in terms ofas.*()not the other way around.