Rev 84142 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
% File src/library/base/man/chooseOpsMethod.Rd% Part of the R package, https://www.R-project.org% Copyright 1995-2023 R Core Team% Distributed under GPL 2 or later\name{chooseOpsMethod}\title{Choose the Appropriate Method for Ops}\alias{chooseOpsMethod}\alias{chooseOpsMethod.default}\usage{chooseOpsMethod(x, y, mx, my, cl, reverse)}\description{\code{chooseOpsMethod} is a function called by the \code{Ops} Group Generic when twosuitable methods are found for a given call. It determines which method touse for the operation based on the objects being dispatched.The function is first called with \code{reverse = FALSE}, where\code{x} corresponds to the first argument and \code{y} to the secondargument of the group generic call. If \code{chooseOpsMethod()} returns\code{FALSE} for \code{x}, then \code{chooseOpsMethod} is called again,with \code{x} and \code{y} swapped, \code{mx} and \code{my} swapped,and \code{reverse = TRUE}.}\arguments{\item{x, y}{the objects being dispatched on by the group generic.}\item{mx, my}{the methods found for objects \code{x} and \code{y}.}\item{cl}{the call to the group generic.}\item{reverse}{logical value indicating whether \code{x} and \code{y} arereversed from the way they were supplied to the generic.}}\seealso{\code{\link[=S3groupGeneric]{Ops}}}\value{This function must return either \code{TRUE} or \code{FALSE}. A value of\code{TRUE} indicates that method \code{mx} should be used.}\keyword{methods}\examples{# Create two objects with custom Ops methodsfoo_obj <- structure(1, class = "foo")bar_obj <- structure(1, class = "bar")`+.foo` <- function(e1, e2) "foo"Ops.bar <- function(e1, e2) "bar"invisible(foo_obj + bar_obj) # Warning: Incompatible methodschooseOpsMethod.bar <- function(x, y, mx, my, cl, reverse) TRUEstopifnot(exprs = {identical(foo_obj + bar_obj, "bar")identical(bar_obj + foo_obj, "bar")})# cleanuprm(foo_obj, bar_obj, `+.foo`, Ops.bar, chooseOpsMethod.bar)}