library(compiler)
"fast<-"=function(`*tmp*`,value)`*tmp*`<-cmpfun(value,list(optimize=3))
在编程的时候用fast(func)=function(...){...}代替func=function(...){...}可以获得1.33-2X的提速
然而问题是,如果这样做,当foo未定义时候
fast(foo)=function(bar)bar
会提示
Error in fast(foo) = function(bar) bar : 找不到对象'foo'
有没有什么解决方法,(让程序发现foo未定义的时候)自动生成一个新的foo
目前的解决方法是用命令fast(foo)=foo=function(bar)bar代替fast(foo)=function(bar)bar
然而这里的问题还是那样……
如果函数比较长……我们需要输入很长一串字符,比如……
fast(`This is a very very long function name to describe what the hell this F**KING function will do`)=
`This is a very very long function name to describe what the hell this F**KING function will do`=function(bar)bar
想知道有没有什么只输入一次变量名就能解决问题的方法
甚至如果能重写function之后实现输入`This is a very very long function name to describe what the hell this F**KING function will do`=function(bar)bar得到的结果就跟实现重写function之前输入library(compiler)
"fast<-"=function(`*tmp*`,value)`*tmp*`<-cmpfun(value,list(optimize=3))
fast(`This is a very very long function name to describe what the hell this F**KING function will do`)=
`This is a very very long function name to describe what the hell this F**KING function will do`=function(bar)bar
的结果,那就更好了