I'd like to pretty-format an R snippet. There's formatR
but because it's based on deparse
there's a lot it cannot actually do, pipe operator %>%
being one of such things. RStudio has great code formatting capabilities but they don't seem to be accessible via any public API.
I checked that the actual code formatting algorithm is implemented in Java (seems to be?) and that there's a bunch of functions that RStudio exposes via rstudioapi
(in C/C++ they seem to start with rs_
). I wonder if there is a way to combine these observations into an R call that will execute code formatting procedure on the currently selected R snippet. I believe I could control the actual selection via the public rstudioapi
API.
And if there's no official way, is there a hacky one?