7

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

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
Egon
  • 3,718
  • 3
  • 34
  • 48

2 Answers2

5

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.

Dirk Eddelbuettel
  • 360,940
  • 56
  • 644
  • 725
  • I am mostly using the np package, and using npplot function in R. When I do try it, with or without sys.sleep(x.x), it creates a file "Rplots.pdf", but it never opens with any pdf reader. – Egon Feb 28 '11 at 14:39
  • Embedding defaults to setting the `interactive` flag to FALSE. I presume you would have to alter that. Or plot to a png file and have widget display that. – Dirk Eddelbuettel Feb 28 '11 at 14:56
1

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

Aquarius_Girl
  • 21,790
  • 65
  • 230
  • 411