2018-08-02-临时替换R包函数相关片段

今天突然知道eval和gsub等函数可以直接说上来用。很开心。。学无止境。。其实每次学到新东西才是最快乐的不是。

https://stackoverflow.com/questions/12925213/prevent-cex-from-scaling-with-the-correlation-coefficient-in-chart-correlation

library("PerformanceAnalytics") ## turn the function into a character 

stringtmpstr <- deparse(chart.Correlation) ## modify the relevant linespanelcorline <- grep("^ *panel.cor",tmpstr)

tmpstr[panelcorline] <-paste(tmpstr[panelcorline],"cex.cor.scale=1,")

rscaleline <- grep("^ *text\\(0.5",tmpstr)

## convert back to a function (don't mask the original function)

tmpstr[rscaleline] <- gsub("cex \\* r","cex*r^cex.cor.scale",tmpstr[rscaleline]) 

my.chart.Correlation <- eval(parse(text=tmpstr))

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容