From paul@stat.auckland.ac.nz  Mon Feb 12 01:27:18 2001
From: paul@stat.auckland.ac.nz (Paul Murrell)
Date: Mon, 12 Feb 2001 14:27:18 +1300
Subject: [Rd] Scatter plot calling R function from C
References: <Pine.GSO.4.31.0102111644480.29747-100000@toucan.stats>
Message-ID: <021301c09492$f32ad320$175dd882@stat.auckland.ac.nz>

Hi


> On Sun, 11 Feb 2001, Tsumiyama Isao wrote:
>
> >  Dear R users,
> >
> >   I want to create a C program drawing a scatter plot
> >   with R functions.
> >
> > Is it possible to do such a thing with interfaces declared
> > in 'Rgraphics.h'? If so, I would like to get sample C sources.
>
> Strictly no.  You would need to open an R graphics device, and you can't
> do that from the publically declared headers.  And you would need to
> handle all the error conditions that call back into R.
>
> From C code called from R you can write to an already opened graphics
> device.  Alternatives, you can embed R in your C program and then call R
> graphics via R calls.
>
> I don't think there are many examples: Rgraphics.h was included for
> use by experts writing addons.  Paul Murrell may be able to help more.


As Brian says, the first big obstacle is getting a device started, which can
only be done from R.  Once you have that, then all of the necessary graphics
is there in Rgraphics.h, but its at a very low level.  Rgraphics.h gives you
access to a basic graphics engine for drawing lines and rectangles and such,
plus some more complicated things like data symbols, but it does not have
anything really high level like a plot or even an axis.  You have to compose
these things yourself.

There are examples of how R uses these functions in R/src/main/plot.c, but
it would take a considerable effort to work out what is going on.

The functions Rgraphics.h exports are useful if you want to write your own
graphics system from the ground up, but they are not very useful if you want
to produce plots like the ones that R already produces.  If you want to do
the latter then you are much better to try the route suggested by Brian and
embed R in your C program so that you can call R's high-level graphics
functions.

Hope that helps

Paul






-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Scatter plot calling R function from C
Paul Murrell