styler icon indicating copy to clipboard operation
styler copied to clipboard

Support for styling .ipynb (IRKernel)

Open MichaelChirico opened this issue 4 years ago • 4 comments
trafficstars

Would support for styling .ipynb files be in scope for styler? Ideally a flow like styler::style_file('/path/to.ipynb') which extracts the code chunks from the JSON & styles them, then writes back out in the correct JSON format.

MichaelChirico avatar Jun 04 '21 19:06 MichaelChirico

I consider this out of scope, mainly because other people already looked into this. E.g. you could use {styler} with the jupyter lab formatter. ~Maybe we should add a note to the~ See thenote in the vignette third-party adoption. Is that what you are looking for?

Another option is contributing a styler integration to prettier.io or coala.io as described in #429, maybe they already have a Jupyter feature to build upon?

lorenzwalthert avatar Jun 04 '21 19:06 lorenzwalthert

You could also use jupytext to save your jupyter notebooks as Rmd or plain R files and apply styler on them.

grst avatar Jun 06 '21 08:06 grst

One reason not to outsource this to Jupyter front-end tooling is that .ipynb is a bit more general format then just Jupyter -- e.g. Colab uses roughly the same format, but it's not clear the same tooling will work interchangeably. Therefore I think it makes some sense for {styler} to own the logic, then the other downstreams can build on that.

Would you accept PR(s) for this? I might do so alongside a similar feature for {lintr}:

https://github.com/r-lib/lintr/issues/383

MichaelChirico avatar Jan 13 '25 20:01 MichaelChirico

Yes, I am open to reviewing a PR from you. Other advantage is that in pre-commit, we’ll be able to extend the styler-hook as well.

lorenzwalthert avatar Jan 14 '25 10:01 lorenzwalthert