Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call R plots from c++ using RInside/ Rcpp

Tags:

r

rcpp

rinside

Is it possible to call the plot functions from the c++ ? 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. 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 ?

Thnx

-Egon

like image 313
Egon Avatar asked Feb 28 '11 13:02

Egon


2 Answers

Yes, there is a working examples in the Rcpp package. Look at the file functionCallback/newApiExample.r in the examples/ directory.
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. It all depends but you gave little detail.

like image 87
Dirk Eddelbuettel Avatar answered Nov 04 '22 04:11

Dirk Eddelbuettel


The environment variable which deals with the interactive session is R_INTERACTIVE_DEVICE.
We need to create a file named .Renviron in our home directory, and then add the following code to that file:

R_INTERACTIVE_DEVICE = X11 for Linux based systems.

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
2. http://stat.ethz.ch/R-manual/R-patched/library/base/html/options.html

like image 1
Aquarius_Girl Avatar answered Nov 04 '22 04:11

Aquarius_Girl