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))

你可能感兴趣的:(2018-08-02-临时替换R包函数相关片段)