NetLogo / SimpleR-Extension

BSD 3-Clause "New" or "Revised" License
3 stars 1 forks source link

Extension is really nice, but a little fragile to R errors? #7

Closed DOSull closed 2 months ago

DOSull commented 3 months ago

I really appreciate the simplicity of configuring this extension, which compared to the original bundled R extension is a breeze.

This really isn't an issue, more a request for any additional guidance on usage. For example, I have found the extension to be fragile to any errors and even warnings in the R code, things such as unplottable points (log scale 0s), or in spatstat points outside the pattern window. When I say fragile I mean that NetLogo can freeze and has to be 'killed' by the OS (this is on MacOS... no idea about other platforms). That can quickly be a source of real frustration!

It would also be good to hear if there are any plans to address this fragility - or perhaps it's impossible in the approach the extension takes (?). If so it would be nice to know more about that also.

Meanwhile, I've found that It is also important to be disciplined in closing plot devices. I have found the following a useful pattern

sr:set-plot-device
;; sr code to create a plot
user-message "Plot will close when you close this dialog."
  
sr:run "dev.off()"

 

This pattern was particularly useful when I was using par(mfrow = c(...)) R calls to make multiplanel plots, where I found that failing to close the plot device explicitly was another source of NetLogo freezes.

I have also found that for ggplot2 plots I can only produce them by saving to file.

Anyway... again, not so much an issue more a comment, and request for any additional information about ongoing development of this extension to perhaps make it a bit more robust.

edmizac commented 3 months ago

Indeed it freezes with any warning. It makes debugging quite painful. I believe I have signalled this here on github by the end of 2022.

The only way I have found to avoid these unwelcomed freezings was to wrap the code with suppressMessage(). Be aware that these warnings might be important (especially the spatstat ones). Hope this helps.

LaCuneta commented 3 months ago

I just merged a fix for the issue with hangs on warnings from R. I suspect that will also resolve #4, but I don't have time to fully test those scenarios now.

I plan to release these changes to the extensions manager once #6 is also addressed. I'll update here once that is done.

DOSull commented 2 months ago

Great! Definitely a real debugging pain as @edmizac pointed out, so will make a huge difference to the usefulness of this extension.

LaCuneta commented 2 months ago

@DOSull Okay, as I was unable to resolve the duplicate menu entry issue, I went ahead and released the "hang on warning" fix with SimpleR 2.0.4 to the extensions manager. If you can give it a try and see if it eases some of the pains you've been having, that'd be great. I don't expect this to resolve the plotting issues you mentioned, and if not, then we may need to open a new issue to track those separately.

@edmizac If you get a chance to re-test your issue, too, with 2.0.4, and update with what you find that'd be much appreciated.

Thanks to you both.

DOSull commented 2 months ago

Yes, this definitely helps the debugging loop.

A warning in R causes the warning to appear in the NetLogo console but the model no longer hangs as it did before. If the warning occurs during plotting, I can kill the R plot window and keep going. An error in R causes a NetLogo extensions error dialogue to appear, and when I dismiss it I can continue working on the model.

I tested by introducing simple R errors/warnings (e.g. plotting a non-existent variable, specifying a parameter in a function call that is not known, creating a spatstat point pattern with points outside the window), and all of these did not cause NetLogo to hang as it previously did.

At least until I see something else, that fixes this issue. Thank you!

LaCuneta commented 2 months ago

Thank you for the update! Closing this, but feel free to add more info or open a new issue if you find something else.