AbuseMethod: Dispatcher for high-level API functions

Description Usage Arguments Details Value Author(s) See Also Examples

Description

Used for library authors defining very high-level API functions. Not typically needed for normal development.

Usage

1
AbuseMethod(fn.name, type, ..., EXPLICIT = FALSE, ALWAYS = TRUE)

Arguments

fn.name

The parent function name. This is just the name of the original function

type

The target type or a regular value from which the type is derived

...

Arguments to pass to the dispatched function

EXPLICIT

Whether the type is passed in explicitly or not

ALWAYS

Whether a default function should be called if all else fails

Details

This alternative dispatching is for specialized purposes. It allows certain syntactic sugar not possible in UseMethod when performing method dispatching. If none of the above made sense, then don't use this function. Otherwise, it can be useful when defining very high-level functions that define interfaces for an API.

In the future this function may take on additional functionality to manage dispatching certain functions based on computer/network architecture.

Value

Returns the result of the dispatched function. When ALWAYS is FALSE, no default function will be called. Instead, an error message is printed. In certain circumstances this fail-fast behavior is preferred over the default lenient behavior.

Author(s)

Brian Lee Yung Rowe

See Also

UseMethod, UseFunction

Examples

1
2
3
4
5
6
7
# Trivial example for pedagogical reasons only
product <- function(...) AbuseMethod('product', ...)

product.numeric <- function(a,b) a * b
product.matrix <- function(a,b) a 

product(4,2)

futile.paradigm documentation built on May 2, 2019, 10:37 a.m.