Skip to content

Feature request: expand S7_inherits to accept additional S7 classes for class parameter #556

@dgkf

Description

@dgkf

S7_inherits currently requires that the class parameter be a <S7_class>, which excludes many of the useful class_*es exported by S7 such as:

S7_base_class

> S7_inherits(1L, class_integer)
#> Error in S7::S7_inherits(1L, class_integer) :
#>  `class` must be an <S7_class> or NULL

S7_S3_class

> S7_inherits(structure(list(), class = "test"), new_S3_class("test"))
#> Error in S7_inherits(structure(list(), class = "test"), new_S3_class("test")) :
#>  `class` must be an <S7_class> or NULL

S7_union

This one's definitely more debatable. If not S7_inherits, having an alternative that allows individual value type checking using the same internals that S7 would use for dispatch, such as S7_is(1L, union_integer_or_character)

> union_integer_or_character <- new_union(class_integer, class_character)
> S7_inherits(1L, union_integer_or_character)
#> Error in S7_inherits(1L, union_integer_or_character) :
#>  `class` must be an <S7_class> or NULL

S7_any

These next two might seem silly, but if we have higher-kinded classes that accept classes as properties, then allowing them to use classes without having to handle specific cases is very useful.

> S7_inherits("test", class_any)
#> Error in S7_inherits("test", class_any) :
#>  `class` must be an <S7_class> or NULL

S7_missing

> x <- bquote()
> missing(x)
#> [1] TRUE
> S7_inherits(x, class_missing)
#> Error in S7_inherits(x, class_missing) :
#>  `class` must be an <S7_class> or NULL

I've been on a deep dive using S7 for a package recently and am carving out time to file feedback today. Sorry for the influx of new issues - loving the package overall 🙌

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions