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

Duncan Murdoch murdoch@dunc@n @end|ng |rom gm@||@com
Fri Feb 3 11:40:20 CET 2023


On 02/02/2023 7:24 p.m., Simon Urbanek wrote:
> 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.

Thanks.  Yours appears to have the advantage of being able to run R code 
in the middle of a function call if that function calls R_ProcessEvents, 
as Sys.sleep() does.  I wonder why "later" didn't support that?

What I was hoping for would be something like R_PolledEvents, but it 
should work on all systems, not just Unix-alikes.  My goal is to 
simplify rgl.  Part of this means I'd like to minimize the system 
dependence, since I no longer have easy access to a Windows machine for 
testing.

Duncan

> 
> Cheers,
> Simon
> 
> [1] - https://github.com/s-u/background
> 
> 
>> On Feb 3, 2023, at 10:53 AM, Duncan Murdoch <murdoch.duncan using gmail.com> 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 using r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-package-devel
>>
>



More information about the R-package-devel mailing list