Dear ESS users and developers,
answering my own request, this is what I came up with:
(defun my-r-styler ()
"Style the current buffer's file (.R, .Rmd, .Rnw) with the styler R
package."
(interactive "*")
(shell-command (concat "Rscript --slave --no-restore --quiet
--no-init-file -e \"styler::style_file('" (buffer-file-name) "')\""))
(revert-buffer nil t)
)
That does the job for me. I still think it would be cool to have
something like this ready-to-use in the ESS package. What do you think?
Admittedly, the function would need to be improved: for example, it
should check, whether the styler package is installed and if not tell
the user about the requirement to install it. Also, I don't know how to
make it run on Windows.
Sven
Am 04.09.20 um 18:43 schrieb Sven Hartenstein via ESS-help:
Dear ESS users and developers,
I would like to -- from within ESS -- use the R package styler
(https://styler.r-lib.org) to format R and Rmd files according to the
tidyverse formatting rules.
As the above mentioned website sais, there is the emacs package
https://github.com/lassik/emacs-format-all-the-code which can format R
files by parsing them through styler. This works well with R
files. However, I have no luck with this package and Rmd (Rmarkdown)
files.
(1) Has anyone managed to use styler for Rmd files from within Emacs?
(2) Wouldn't this be a cool feature of ESS to be able to parse the
current buffer through styler? (I guess it should be rather easy to
parse the current buffer through a R function, but my programming skills
do not suffice.)
Best,
Sven
______________________________________________
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help
______________________________________________
ESS-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/ess-help