一開始想直接把R編譯成庫然後呼叫R,後來查了n多資料,發現VS中是無法辦到的,官方也給出了一句話,大概意思就是沒可能在VS中使用R提供的C++介面,大概是涉及到了底層的ABI的原因,具體也不太清楚。
於是就想到了直接採用新建檔案然後寫成.R指令碼的方式來呼叫R,這種使用方式必須安裝R,然後從程式內部呼叫RScript.exe以及相應指令碼。
QFile Rfile("C:\\temp\\RScript\\heatmap.R");
Rfile.open(QIODevice::WriteOnly);
QTextStream RfileWrite(&Rfile);
RfileWrite << "library(RColorBrewer)" << endl;
RfileWrite << "library(gplots)" << endl;
RfileWrite << "x = read.table(\"C:\\\\temp\\\\RData\\\\heatmap.dat\", header = TRUE, sep=\"\t\")" << endl;
RfileWrite << "mat = data.matrix(x)" << endl;
RfileWrite << "png(file = \"C:\\\\temp\\\\RPic\\\\heatmap.png\", bg = \"transparent\")" << endl;
RfileWrite << "heatmap.2(mat, Rowv = TRUE, Colv = TRUE, distfun = dist,hclustfun = hclust,\
xlab = \"X data\", ylab = \"Y data\",\
key = TRUE,\
keysize = ,\
trace = \"none\",\
density.info = c(\"none\"),\
margins = c(, ),\
col = brewer.pal(, \"PiYG\")\
)"<<endl;
RfileWrite << "dev.off()" << endl;
Rfile.flush();
Rfile.close();
//system("C:\\\"program files\"\\R\\R-3.1.2\\bin\\RScript D:\\drawtest.R");
//system("RScript D:\\drawtest.R");
ShellExecuteA(NULL, "open", "RScript.exe", "C:\\temp\\RScript\\heatmap.R", NULL, SW_HIDE);