Special Functions in R

Special Functions

Special functions are really standard functions in practice, but they are user defined functions that serve to expand the range of infix operators, extraction, and replacement functions in R.

Custom Infix Operators

R can be used to create or define new infix operators with the format %anything%.  These operators extend base functionality as needed.  For example, the code below defines an new operator that raises a matrix to a power:

Use the get() function to review and print the details of the custom function.

Custom Attribute Extraction and Replacement Functions

R has many extraction and replacement functions.  Newly created functions are needed when data objects are customized with new attributes or meta data.

As a simple example, suppose we want to create a replacement function that assigns a new attribute named memo to the data object.  memo is intended to hold a brief description of a data object and its variables. Next, the corresponding extraction function is defined to retrieve the memo attribute assigned to the data.  Both functions start naturally enough with the attr() function:

Back | Next