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: