Skip to content

Cannot implement unary Ops methods #531

@teunbrand

Description

@teunbrand

The following attempt at making a unary method for - fails:

library(S7)

foo <- new_class("foo")
method(`-`, list(foo, class_missing)) <- function(e1, e2) {"Minus foo"}

-foo()
#> Error in Ops.S7_object(foo()): argument "e2" is missing, with no default

Created on 2025-03-28 with reprex v2.1.1

I think the cause is that the following lines don't consider the possibility of missing e1 or e2.

S7/R/method-ops.R

Lines 19 to 22 in db59642

cnd <- tryCatch(
return(base_ops[[.Generic]](e1, e2)),
S7_error_method_not_found = function(cnd) cnd
)

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