简体   繁体   English

使用RInside / Rcpp从C ++调用R图

[英]Call R plots from c++ using RInside/ Rcpp

Is it possible to call the plot functions from the c++ ? 是否可以从c ++调用plot函数? Currently when I try to do that, the ubuntu terminal sort of freezes for sometime ( may be the duration for which the 3d plot would be created and then rotated for a full 360 degrees) and then unfreezes, without ever popping a new window. 目前,当我尝试执行此操作时,ubuntu终端会冻结一段时间(可能是创建3d绘图然后旋转360度的持续时间),然后冻结,而从未弹出新窗口。 Is this the expected behavior or is there something that I am doing wrong ? 这是预期的行为还是我做错了什么? How can I get the plots ( R graphics ) to run from within c++ using rinside and rcpp ? 如何使用rinside和rcpp在C ++中运行图(R图形)?

Thnx n

-Egon -伊贡

Yes, there is a working examples in the Rcpp package. 是的,Rcpp软件包中有一个有效的示例。 Look at the file functionCallback/newApiExample.r in the examples/ directory. 查看examples/目录中的文件functionCallback/newApiExample.r
You may need to experiment with sleep() to 'hold' the plot for a moment, or plot to a file and then have the file displayed. 您可能需要尝试使用sleep()暂时保留该图,或者将其绘制到文件中,然后显示文件。 It all depends but you gave little detail. 一切都取决于您,但您没有提供任何细节。

The environment variable which deals with the interactive session is R_INTERACTIVE_DEVICE . 处理交互式会话的环境变量是R_INTERACTIVE_DEVICE
We need to create a file named .Renviron in our home directory, and then add the following code to that file: 我们需要在主目录中创建一个名为.Renviron的文件,然后将以下代码添加到该文件中:

R_INTERACTIVE_DEVICE = X11 for Linux based systems. R_INTERACTIVE_DEVICE = X11用于基于Linux的系统)。

anisha@linux-y3pi:~> ls .Renviron
.Renviron

anisha@linux-y3pi:~> cat .Renviron
R_INTERACTIVE_DEVICE = X11a

References: 参考文献:
1. http://stat.ethz.ch/R-manual/R-patched/library/base/html/Startup.html 1. http://stat.ethz.ch/R-manual/R-patched/library/base/html/Startup.html
2. http://stat.ethz.ch/R-manual/R-patched/library/base/html/options.html 2. http://stat.ethz.ch/R-manual/R-patched/library/base/html/options.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM