Skip to content

convert() should be idempotent when from is an instance of to #429

@lawremi

Description

@lawremi

If from is an instance of to, i.e., identical(S7_class(from), to) is TRUE (assuming from is an S7 object), then no dispatch should occur.

This is not (just) about efficiency. If there are convert() methods for downcasting to to, one of them will be called even if there is no need to downcast, potentially resulting in data being overwritten, or other weird things happening.

I'll also note that methods::as() is idempotent when to is class_any, but class_any is not allowed with convert(). Somewhat pedantic, but I thought it was worth mentioning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions