r-wasm / jupyterlite-webr-kernel

An R kernel for JupyterLite, based on webR.
https://r-wasm.github.io/jupyterlite-webr-kernel/
MIT License
39 stars 7 forks source link

Generating multiple responses from multiple lines of code in a notebook code cell #11

Open psychemedia opened 3 weeks ago

psychemedia commented 3 weeks ago

In IPython notebooks, code cell outputs display any object returned by the last line of code in the block.

In the Jupyter IRkernel, response objects are displayed from each response generating line of code:

image

In the jupyterlite-webr-kernel, we seem to follow the behaviour of the IPython kernel rather than the IRkernel:

image

As does the xeus R kernel:

image

Does the webr kernel return the multiple values, so that they could all be displayed, as per the IRkernel model, or does it just return the final value?

Actually, is the IRkernel displaying values as they are returned, rather than returning a result from the code cell? IRkernel behaviour described here: https://github.com/IRkernel/IRkernel/issues/225 Seems like the IRkernel folk are maybe doing something atypical...

georgestagg commented 3 weeks ago

The webR kernel returns only the final value right now. I think it would be a good feature to switch to the IRkernel style, also similar to the output when using knitr to render R Markdown.

This should be possible by setting up the webR kernel to execute code with the evaluate package. Then a single input cell could generate multiple outputs. Perhaps this should all be behind a setting, too, since as you have discovered this is not the default behaviour and probably something that IRkernel is explicitly adding themselves.

psychemedia commented 2 weeks ago

I think that having it as a setting would be a courteous thing to do. I am firmly in the "one output" camp, but working with someone who has only known the IRKernel approach and sees that as a more R idiomatic response.

It might even be useful to allow it as a user preference via a JupyterLab user setting, but that adds quite a lot of complexity and effort.