[R-pkg-devel] run a function from a list

Iñaki Úcar i.ucar86 at gmail.com
Sat May 27 15:07:53 CEST 2017


Hi Glenn,

Try this:

my_list <- list(func = eval(parse(text=paste0("function()",
"print('this is a function')"))))
my_list$func()
#> "this is a function"

Regards,
Iñaki

2017-05-27 14:49 GMT+02:00 Glenn Schultz <glennmschultz at me.com>:
> 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



-- 
Iñaki Úcar
http://www.enchufa2.es
@Enchufa2



More information about the R-package-devel mailing list