一开始想直接把R编译成库然后调用R,后来查了n多资料,发现VS中是无法办到的,官方也给出了一句话,大概意思就是没可能在VS中使用R提供的C++接口,大概是涉及到了底层的ABI的原因,具体也不太清楚。
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 = 2,trace = \"none\",\
density.info = c(\"none\"),\
margins = c(5, 5),col = brewer.pal(10, \"PiYG\")\
)"<
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);