decorators: Extend the Behaviour of a Function without Explicitly Modifying it

A decorator is a function that receives a function, extends its behaviour, and returned the altered function. Any caller that uses the decorated function uses the same interface as it were the original, undecorated function. Decorators serve two primary uses: (1) Enhancing the response of a function as it sends data to a second component; (2) Supporting multiple optional behaviours. An example of the first use is a timer decorator that runs a function, outputs its execution time on the console, and returns the original function's result. An example of the second use is input type validation decorator that during running time tests whether the caller has passed input arguments of a particular class. Decorators can reduce execution time, say by memoization, or reduce bugs by adding defensive programming routines.

Getting started

Package details

AuthorHarel Lustiger [aut, cre] (<https://orcid.org/0000-0003-2953-9598>), Tidylab [cph, fnd]
MaintainerHarel Lustiger <tidylab@gmail.com>
LicenseMIT + file LICENSE
Version0.3.0
URL https://tidylab.github.io/decorators/ https://github.com/tidylab/decorators
Package repositoryView on CRAN
Installation Install the latest version of this package by entering the following in R:
install.packages("decorators")

Try the decorators package in your browser

Any scripts or data that you put into this service are public.

decorators documentation built on Sept. 30, 2022, 5:06 p.m.