美文网首页R--随处收藏
2018-08-02-临时替换R包函数相关片段

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

作者: zouxiaoyu | 来源:发表于2018-08-02 08:18 被阅读0次

    今天突然知道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包函数相关片段

        本文链接:https://www.haomeiwen.com/subject/qbzdvftx.html