[R-pkg-devel] run a function from a list
Richard M. Heiberger
rmh at temple.edu
Sun May 28 20:56:46 CEST 2017
Your quote symbols are certainly getting in the way.
try basing your next version on something like this,
where the items in the list named tmp are actual functions, not
character strings.
> tmp <- list(prob=pnorm, quantile=qnorm)
> tmp$prob(1.96)
[1] 0.9750021
> tmp$quantile(.975)
[1] 1.959964
On Sat, May 27, 2017 at 8:49 AM, Glenn Schultz <glennmschultz at me.com> wrote:
> All,
> I have a function to split a fixed rate bond into a floater/inverse floater
> combination (something typically done in mortgage securtizations). The
> function returns a list which serves as the deal structure over which
> principal payment rules will iterate. However, I would like to call the
> functions as they drive the interest coupon payments. I am using paste0()
> to piece together the function and I think the problem is the quotes but not
> sure.
>
> I have tried source, do.call, list$foo(), list[[]](). None of these have
> worked. Any advice on structuring this problem is appreciated.
>
> Thanks,
> Glenn
>
> structure(list(floater.balance = 30.78, floater.cap = 6.66666666666667,
> floater.floor = 0.3, floater.index = "1mLIBOR", floater.formula =
> "function(index){min(6.67,max((1mLIBOR+0.3)0.3))}", inverse.balance = 20.52,
> inverse.cap = 9.55, inverse.multipler = 1.5, inverse.floor = 0,
> inverse.floater.formula = "(function(index)
> {min(9.55,max((-1.5*1mLIBOR)+9.55,0))})"), .Names = c("floater.balance",
> "floater.cap", "floater.floor", "floater.index", "floater.formula",
> "inverse.balance", "inverse.cap", "inverse.multipler", "inverse.floor",
> "inverse.floater.formula"))
>
>
>
>
> ______________________________________________
> R-package-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
More information about the R-package-devel
mailing list