[R-pkg-devel] Best current way to hook into the event loop?

2023-02-02 Thread Duncan Murdoch
I'm updating low level stuff in the rgl package.  I'm exploring using 
the GLFW library to handle low level stuff instead of trying to do that 
myself.


Currently rgl has fairly ugly code to link into the R event loop.  (It 
needs to do this so that it hears about mouse movement, etc.)  I'm 
hoping that someone else has written better code than I could to do 
this.  Is there a currently recommended way to hook into the loop?


The kinds of things I need are getting events fairly frequently (e.g. 
0.03 second delay if things aren't too busy) for code that doesn't 
involve R at all.


I will also occasionally want to call back into R; I don't really mind 
if there's a bigger delay to wait for that to be safe.


I've seen the "later" package:  it looks as though it might do what I 
need, but the protection for R code seems to be all or nothing, i.e. if 
I want to evaluate an R expression nothing else can be running, or if I 
want action while R code is running, I can't involve R at all.


Duncan Murdoch

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel


Re: [R-pkg-devel] Best current way to hook into the event loop?

2023-02-02 Thread Simon Urbanek
Duncan,

I don't know if it is best, but you can have a look at "background"[1] which is 
I believe what "later" was inspired by. It is a very minimal example so should 
give you ideas on how to do that in your package - it runs the R code on the 
main thread so it should be as close to safe as one can get with asynchronous 
calls, just beware of reentrance. In your case I suspect that you may already 
have an X11 fd that you can use in the unix handler - not sure what signaling 
you need on Windows, though.

Cheers,
Simon

[1] - https://github.com/s-u/background


> On Feb 3, 2023, at 10:53 AM, Duncan Murdoch  wrote:
> 
> I'm updating low level stuff in the rgl package.  I'm exploring using the 
> GLFW library to handle low level stuff instead of trying to do that myself.
> 
> Currently rgl has fairly ugly code to link into the R event loop.  (It needs 
> to do this so that it hears about mouse movement, etc.)  I'm hoping that 
> someone else has written better code than I could to do this.  Is there a 
> currently recommended way to hook into the loop?
> 
> The kinds of things I need are getting events fairly frequently (e.g. 0.03 
> second delay if things aren't too busy) for code that doesn't involve R at 
> all.
> 
> I will also occasionally want to call back into R; I don't really mind if 
> there's a bigger delay to wait for that to be safe.
> 
> I've seen the "later" package:  it looks as though it might do what I need, 
> but the protection for R code seems to be all or nothing, i.e. if I want to 
> evaluate an R expression nothing else can be running, or if I want action 
> while R code is running, I can't involve R at all.
> 
> Duncan Murdoch
> 
> __
> R-package-devel@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-package-devel
> 

__
R-package-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-package-devel