Learn R Programming

VGAM (version 0.9-0)

smart.expression: S Expression for Smart Functions

Description

smart.expression is an S expression for a smart function to call itself. It is best if you go through it line by line, but most users will not need to know anything about it. It requires the primary argument of the smart function to be called "x".

The list component match.call must be assigned the value of match.call() in the smart function; this is so that the smart function can call itself later.

Arguments

See Also

match.call.

Examples

Run this code
"my2" <- function(x, minx=min(x)) { # Here is a smart function
    x <- x  # Needed for nested calls, e.g., bs(scale(x))
    if(smart.mode.is("read")) {
        return(eval(smart.expression))
    } else
    if(smart.mode.is("write"))
        put.smart(list(minx=minx, match.call=match.call()))
    (x-minx)^2
}
attr(my2, "smart") <- TRUE

Run the code above in your browser using DataLab