• VS中使用QT调用R脚本


      一开始想直接把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="	")" << 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")
    )"<<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);
  • 相关阅读:
    Qt项目时隔数月再次打开竟出现bug
    软件测试分类
    为什么要搭建自动化测试框架
    黑盒测试常用方法
    软件测试:闰年判断
    等价类划分的应用
    软件测试学习第二周:等价类划分
    软件测试的目的
    软件测试学期总结
    集成测试深度理解
  • 原文地址:https://www.cnblogs.com/yanqi0124/p/4099347.html
Copyright © 2020-2023  润新知