Learn R Programming

decisionSupport (version 1.114)

plainNames2data.frameNames: Transform model function variable names: plain to data.frame names.

Description

The variable names of a function are transformed from plain variable names to data.frame names of the form x$<globalName>.

Usage

plainNames2data.frameNames(modelFunction, plainNames)

Value

The transformed function which is of the form:


   function(x){
     ...
     <expression with x$variable1>
     ...
   }
 

Arguments

modelFunction

a function whose body contains variables with plain names. The function must not contain any arguments.

plainNames

a character vector containing the names of the variables that shall be transformed.

Warning

If there are local functions within the function modelFunction defined, whose arguments have identical names to any of the plainNames the function fails!

Details

The input function must be of the form:


   modelFunction<-function(){
     ...
     <expression with variable1>
     ...
   }
 

See Also

mcSimulation, estimate

Examples

Run this code
 profit1<-function(){
   list(Profit=revenue-costs)
 }
 profit2<-plainNames2data.frameNames(modelFunction=profit1, 
                                               plainNames=c("revenue", "costs"))
 print(profit2)
 is.function(profit2)
 profit2(data.frame("revenue"=10,"costs"=2))

Run the code above in your browser using DataLab