Learn R Programming

pragma (version 0.1.3)

setPragma: Function that returns a pragma

Description

setPragma allows for the use of pragma (also sometimes called directives or keywords. These allow assigning arbitrary functionality without having to use R's standard function call syntax i.e. with parens, resulting in cleaner code.

Usage

setPragma(name,fun)

Arguments

name
The name given to the pragma/directive.
fun
A function providing the functionality to be executed. The function should have no arguments.

Value

An object that when encountered in the flow of the program will execute the supplied function without the need for parenthesis. The object should be assigned to a KEYWORD that can then be exported from a package.

Warning

setPragma departs significantly from standard R language conventions in which every action appears as a function and side-effects are assiduously avoided.

Details

Pragmas are useful for implementing assigning a small bit code that requires no parameters. Pragmas are implemented as object in their own unique class. The default (show) method is set to the user-supplied function. When, during the course of the program flow, the pragma is used, the arbitrary functionality is executed.

setPragma departs significantly from standard R language conventions in which every action appears as a function and side-effects are assiduously avoided.

References

http://en.wikipedia.org/wiki/Pragma

http://en.wikipedia.org/wiki/Directive_(programming)

See Also

Nothing to see here, move along.

Examples

Run this code
   
   ## Not run:  
#      setPragma( "KEYWORD", function() { cat( "Do Something Special.\n" ) } )
#      KEYWORD  
#    ## End(Not run)

Run the code above in your browser using DataLab