如何在r中使用gridExtra中的tableGrob对象

时间:2015-05-08 17:30:17

标签: r gridextra grob

我想重新使用tableGrobgridExtra包中的r对象的主题/模板/默认值。

library(gridExtra)

tableGrob(df, cols = c("Custom Name", "Custom Name2"), 
          show.rownames = FALSE, h.even.alpha = 0)

tableGrob(df2, cols = c("Different Name", "Different Name2"), 
          show.rownames = FALSE, h.even.alpha = 0)

注意,我不想多次重复show.rownames = FALSEh.even.alpha = 0。创建某种类型的主题或模板的适当方法是什么,以避免在对tableGrob的不同调用中重复这些选项?我可以使用类似于ggplot2的主题来做这件事,还是我最好的选择?

1 个答案:

答案 0 :(得分:2)

您可以定义一个新函数,将固定参数设置为您想要的值,并且只需要您提供数据框和列名称:

tg1 = myTG(df, c("Custom Name 1", "Custom Name 2"))

然后运行它:

public enum Something {
a,
b,
c;

public static class Bound implements QueryStringBindable<Bound>{
   private Something value;

    @Override
    public F.Option<Bound> bind(String key, Map<String, String[]> params) {
        String[] arr = params.get(key);
        if (arr != null && arr.lenght > 0) {
            this.value = Something.valueOf(arr[0]);
            return F.Option.Some(this);
        } else {
            return F.Option.None();
        }
    }

    @Override
    public String unbind(String key) {
        return key + "=" + this.value.name();
    }

    @Override
   public String javascriptUnbind() {
        return this.value.name();
   }

   public Something value(){
       return this.value;
   }
}