[Rd] User Input

Glenn Schultz glennmschultz at me.com
Sat Jul 11 04:03:47 CEST 2015


All,

I have a package BondLab, all variables are passed to the models via Cusip objects.  

The only variables input by the user are 
settlement date, 
price or yield or spread.  

Further price may be passed as 100.125, 100-8 (1/8), or 100-2 (2/64) or 100-2+ (5/128). 

Once passed these variables must have a steady state (in decimal).  After reading the R documentation and Hadley's book I think the way to do this is via a class but I can quite get my head around how to do it.  A nominal model is:

Analytics <- function(bondid = cusip, tradedate = trade.date, settledate = settle.date, price = 100.125){
BondAnalytics <- BondAnalytics(tradedate = tradedate, settledate = settledate, price = price)
New("BondAnalytics ...)
}  

So, price is an input to a constructor function which calls other functions to create the class object BondAnalytics.  If price is an object with validity how do I make that part of the function?

If I do make it class how does it function input inherit?  I read John Chamber's book but I am not sure... maybe it does not have to be a class but something else or is it something like the below:

BondAnalytics <- function(bond.id = "character", tradedate = "character", settledate = "character", price = .Object){
do stuff...}

Advice appreciated,
-glenn



More information about the R-devel mailing list