0

I'm using R in JupyterLab. Whenever I create functions with ggplot, JupyterLab does not auto-indent my script after the '+' operator. The same holds for when I'm piping: JupyterLab does not auto-indent my script after the '%>%' operator.

What could I do to change this? Is there, perhaps, a GitHub repository out there with a catalog of user settings to make R behave more like it does in RStudio - but in JupyterLab?

Thank you!

1 Answers1

0

This might not be the answer you are looking for, but the way I handle this is using the following notation:

(
    ggplot(data)
    + geom_line()
    + geom_point()
)

This way:

  • you can comment out + geom_point() at any time by only adding # (if the + is at the end, you would need to remove it from previous line)
  • you get consistent auto-indent
  • if you decide to assign the plot to a variable, changing the variable name does not shift the ggplot(data) line (so there is no cascading effect on line length)

As for why it behaves like that when using pipe/plus at the end: it comes down to choices made in CodeMirror R mode. JupyterLab 4 is migrating to CodeMirror 6 which may offer more advanced parsing system, but it currently re-uses the old R mode from CodeMirror 5 - so there is a potential for improvements, but someone would need to undertake some fundamental work first. There is an issue about supporting it in CodeMirror 5 here: https://github.com/codemirror/codemirror5/issues/6671 (but it is unlikely to get fixed since the new development focuses on CodeMirror 6).

As for more other R-specific features, you may be interested in:

krassowski
  • 13,598
  • 4
  • 60
  • 92
  • (of course it could be addressed in CodeMirror 5 mode if you have time to fix that issue/pay someone to do so and the maintainer agrees - it is just my feeling is that they prioritise CM6 now) – krassowski Aug 31 '22 at 19:01