what is the best way for an external interface to interact with graphics, libraries

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

what is the best way for an external interface to interact with graphics, libraries

ghostwheel
Another message about the R to TeXmacs interface.

1. Graphics
The TeXmacs interface allows the user to directly insert graphics into the session.

Since I am not very familiar with programming for R, I implemented the interaction with graphics in a very primitive way. It was two modes of working: with X11, and without (for example when working remotely through ssh without forwarding X11).

In both cases the user has to invoke a command, v(), in order to insert the current graph into the buffer at the current place.

With X11, the way it works is that when v() is invoked I call recordPlot(), then open a postscript file, then replayPlot(), and then close the postscript file and insert it into the session.

Without X11, I open a postscript file ahead of time, then when v() is called, I close it, and insert it into the session, and then open a new postscript file.

Obviously quite primitive.I think ideally would be if everything was transparent to the user - the user does a plot, and the plot is inserted into the buffer right away, and later, updates to the same plot update the original plot where it is. But to be able to do that I need to be able to generate the postscript file of the current plot, and be notified somehow whenever the plot changes.

Is all that possible? Is there a better way to implement this all?

2. Libraries

A remotely related question is this: the interface with TeXmacs generates menus that depend on the currently loaded libraries. I'd like to be able to update the menus whenever a new library is loaded. Is there a possibility to have a function called whenever this happens? Or would it be advisable to change the global 'library' function?
Reply | Threaded
Open this post in threaded view
|

Re: what is the best way for an external interface to interact with graphics, libraries

Simon Urbanek

On Sep 7, 2010, at 2:21 PM, ghostwheel wrote:

>
> Another message about the R to TeXmacs interface.
>
> 1. Graphics
> The TeXmacs interface allows the user to directly insert graphics into the
> session.
>
> Since I am not very familiar with programming for R, I implemented the
> interaction with graphics in a very primitive way. It was two modes of
> working: with X11, and without (for example when working remotely through
> ssh without forwarding X11).
>
> In both cases the user has to invoke a command, v(), in order to insert the
> current graph into the buffer at the current place.
>
> With X11, the way it works is that when v() is invoked I call recordPlot(),
> then open a postscript file, then replayPlot(), and then close the
> postscript file and insert it into the session.
>
> Without X11, I open a postscript file ahead of time, then when v() is
> called, I close it, and insert it into the session, and then open a new
> postscript file.
>
> Obviously quite primitive.I think ideally would be if everything was
> transparent to the user - the user does a plot, and the plot is inserted
> into the buffer right away, and later, updates to the same plot update the
> original plot where it is. But to be able to do that I need to be able to
> generate the postscript file of the current plot, and be notified somehow
> whenever the plot changes.
>
> Is all that possible? Is there a better way to implement this all?
>

I don't know the mechanics of the actual "inserting" in TeXmac but it would be trivial to simply create a copy of the plot as EPS (or whatever is needed) at the time of insertion. See dev.copy2eps() for a function that does exactly that.



> 2. Libraries
>
> A remotely related question is this: the interface with TeXmacs generates
> menus that depend on the currently loaded libraries.

Libraries are not "loaded" (see .libPath() for handling libraries) - but chances are that you meant packages...


> I'd like to be able to
> update the menus whenever a new library is loaded. Is there a possibility to
> have a function called whenever this happens? Or would it be advisable to
> change the global 'library' function?
>

I would strongly advise against the latter. A reasonably simple way would be to check the search path - if it changed a package has been loaded. A natural place to do such check would be in a top-level task handler for example.

Cheers,
Simon

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: what is the best way for an external interface to interact with graphics, libraries

ghostwheel
Simon Urbanek wrote
I don't know the mechanics of the actual "inserting" in TeXmac but it would be trivial to simply create a copy of the plot as EPS (or whatever is needed) at the time of insertion. See dev.copy2eps() for a function that does exactly that.
Great. It works much better than my recordPlot() hack. But it seems to only work for 'screen devices'. I'd like to be able to work remotely without X11. Is there any equivalent graphics device that would be copyable with dev.copy2eps?  Is there any way to tell R give me whatever you have till now in eps?

Reply | Threaded
Open this post in threaded view
|

Re: what is the best way for an external interface to interact with graphics, libraries

Simon Urbanek

On Sep 7, 2010, at 3:07 PM, ghostwheel wrote:

>
>
> Simon Urbanek wrote:
>>
>>
>> I don't know the mechanics of the actual "inserting" in TeXmac but it
>> would be trivial to simply create a copy of the plot as EPS (or whatever
>> is needed) at the time of insertion. See dev.copy2eps() for a function
>> that does exactly that.
>>
>>
>
> Great. It works much better than my recordPlot() hack. But it seems to only
> work for 'screen devices'. I'd like to be able to work remotely without X11.
> Is there any equivalent graphics device that would be copyable with
> dev.copy2eps?  Is there any way to tell R give me whatever you have till now
> in eps?
>

No (AFAIR PS devoice does not keep a display list).

However, you can use any other device that uses a display list, e.g. CairoPS from the Cairo package (in fact any of the Cairo devices..).

Cheers,
Simon

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: what is the best way for an external interface to interact with graphics, libraries

Paul Murrell
Hi

On 8/09/2010 9:23 a.m., Simon Urbanek wrote:

>
> On Sep 7, 2010, at 3:07 PM, ghostwheel wrote:
>
>>
>>
>> Simon Urbanek wrote:
>>>
>>>
>>> I don't know the mechanics of the actual "inserting" in TeXmac but it
>>> would be trivial to simply create a copy of the plot as EPS (or whatever
>>> is needed) at the time of insertion. See dev.copy2eps() for a function
>>> that does exactly that.
>>>
>>>
>>
>> Great. It works much better than my recordPlot() hack. But it seems to only
>> work for 'screen devices'. I'd like to be able to work remotely without X11.
>> Is there any equivalent graphics device that would be copyable with
>> dev.copy2eps?  Is there any way to tell R give me whatever you have till now
>> in eps?
>>
>
> No (AFAIR PS devoice does not keep a display list).

PS device does not keep a display list *by default*.  You should be able
to turn it on via ...

dev.control("enable")

Paul

> However, you can use any other device that uses a display list, e.g. CairoPS from the Cairo package (in fact any of the Cairo devices..).
>
> Cheers,
> Simon
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel

--
Dr Paul Murrell
Department of Statistics
The University of Auckland
Private Bag 92019
Auckland
New Zealand
64 9 3737599 x85392
[hidden email]
http://www.stat.auckland.ac.nz/~paul/

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel
Reply | Threaded
Open this post in threaded view
|

Re: what is the best way for an external interface to interact with graphics, libraries

Michael Lawrence-3
In reply to this post by Simon Urbanek
On Tue, Sep 7, 2010 at 11:34 AM, Simon Urbanek
<[hidden email]>wrote:

>
> On Sep 7, 2010, at 2:21 PM, ghostwheel wrote:
>
> >
> > Another message about the R to TeXmacs interface.
> >
> > 1. Graphics
> > The TeXmacs interface allows the user to directly insert graphics into
> the
> > session.
> >
> > Since I am not very familiar with programming for R, I implemented the
> > interaction with graphics in a very primitive way. It was two modes of
> > working: with X11, and without (for example when working remotely through
> > ssh without forwarding X11).
> >
> > In both cases the user has to invoke a command, v(), in order to insert
> the
> > current graph into the buffer at the current place.
> >
> > With X11, the way it works is that when v() is invoked I call
> recordPlot(),
> > then open a postscript file, then replayPlot(), and then close the
> > postscript file and insert it into the session.
> >
> > Without X11, I open a postscript file ahead of time, then when v() is
> > called, I close it, and insert it into the session, and then open a new
> > postscript file.
> >
> > Obviously quite primitive.I think ideally would be if everything was
> > transparent to the user - the user does a plot, and the plot is inserted
> > into the buffer right away, and later, updates to the same plot update
> the
> > original plot where it is. But to be able to do that I need to be able to
> > generate the postscript file of the current plot, and be notified somehow
> > whenever the plot changes.
> >
> > Is all that possible? Is there a better way to implement this all?
> >
>
> I don't know the mechanics of the actual "inserting" in TeXmac but it would
> be trivial to simply create a copy of the plot as EPS (or whatever is
> needed) at the time of insertion. See dev.copy2eps() for a function that
> does exactly that.
>
>
>
> > 2. Libraries
> >
> > A remotely related question is this: the interface with TeXmacs generates
> > menus that depend on the currently loaded libraries.
>
> Libraries are not "loaded" (see .libPath() for handling libraries) - but
> chances are that you meant packages...
>
>
> > I'd like to be able to
> > update the menus whenever a new library is loaded. Is there a possibility
> to
> > have a function called whenever this happens? Or would it be advisable to
> > change the global 'library' function?
> >
>
> I would strongly advise against the latter. A reasonably simple way would
> be to check the search path - if it changed a package has been loaded. A
> natural place to do such check would be in a top-level task handler for
> example.
>
>
Another possibility would be the setHook() function.

Michael

Cheers,
> Simon
>
> ______________________________________________
> [hidden email] mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>

        [[alternative HTML version deleted]]

______________________________________________
[hidden email] mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel