如何将多个html(有线)表合并为一个图像?

时间:2019-01-03 15:23:04

标签: r knitr kable

我想将多个contents.endText();表合并为一个图像。 像这样:

#include <iostream>

template <typename R, typename ...T>
class Callback
{
public:
    virtual ~Callback() {}
    virtual R operator() (T... args) = 0;
};

template <typename R, typename ...T>
class FreeCallback : public Callback<R, T...>
{
public:
    FreeCallback(R(*func)(T...)) : func_(func) {}
    virtual R operator() (T... args) { return (*func_)(args...); }
private:
    R(*func_)(T...);
};

template <typename tClass, typename R, typename ...T>
class MemberCallback : public Callback<R, T...>
{
public:
    MemberCallback(tClass* instance, R (tClass::*memberfunction)(T...)) : instance_(instance), memberfunc_(memberfunction) {}
    virtual R operator() (T... args) { return (instance_->*memberfunc_)(args...); }
private:
    tClass * instance_;
    R (tClass::*memberfunc_)(T...);
};

class foo {
  public:
  Callback<int, int> *IntCallback;
  Callback<int, int, double, double> *IntDoubleDoubleCallback;
};

class blub {
  public:
  int func1(int i) {
    std::cout << "args: " << i << std::endl;
    return 1;
  }
  int func2(int i, double d1, double d2){
    std::cout << "args: " << i << " " << d1 << " " << d2 << std::endl;
    return 0;
  }
};

  int freeFunc1(int i) {
    std::cout << "args: " << i << std::endl;
    return 1;
  }
  int freeFunc2(int i, double d1, double d2){
    std::cout << "args: " << i << " " << d1 << " " << d2 << std::endl;
    return 0;
  }

int main() {
  foo f;
  blub b;
  f.IntCallback = new MemberCallback<blub, int, int>(&b, &blub::func1);
  f.IntDoubleDoubleCallback = new MemberCallback<blub, int, int, double, double>(&b, &blub::func2);

  Callback<int, int> *IntFreeCallback = new FreeCallback<int, int>(&freeFunc1);
  Callback<int, int, double, double> *IntDoubleDoubleFreeCallback = new FreeCallback<int, int, double, double>(&freeFunc2);

  int ret = (*IntFreeCallback)(42);
  std::cout << "ret freeFunc1: " << ret << std::endl;
  ret = (*IntDoubleDoubleFreeCallback)(42, 3.1415, 2.7182);
  std::cout << "ret freeFunc2: " << ret << std::endl;


  ret = (*f.IntCallback)(42);
  std::cout << "ret func1: " << ret << std::endl;
  ret = (*f.IntDoubleDoubleCallback)(42, 3.1415, 2.7182);
  std::cout << "ret func2: " << ret << std::endl;
  std::cout << "Hello World!\n";
  // cleanup not done here...
}

并在图像中将kable放在library(knitr) library(kableExtra) dt <- mtcars[1:5, 1:4] # first table table1 <- kable(dt, format = "html", caption = "Demo Table") %>% kable_styling(bootstrap_options = "striped", full_width = F) %>% add_header_above(c(" ", "Group 1" = 2, "Group 2[note]" = 2)) %>% add_footnote(c("table footnote")) # second table table2 <- kable(dt, format = "html", caption = "Demo Table") %>% kable_styling(bootstrap_options = "striped", full_width = F) %>% add_header_above(c(" ", "Group 1" = 2, "Group 2[note]" = 2)) %>% add_footnote(c("table footnote")) 上方:

table1

但是,这不起作用。我怎样才能做到这一点? 谢谢!

1 个答案:

答案 0 :(得分:1)

基于this answer,看起来函数cat 可以将多个表组合成html。所以你可以做 kable(c(table1, table2), "html") %>% cat(., file = "P:/mytable/table.html") 然后将 html 转换为 jpg