[ESS] Using the R package styler to format buffer (problems with Rmd files)
||@t@ @end|ng |rom @venh@rten@te|n@de
Tue Nov 3 19:21:57 CET 2020
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
(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.
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)
> (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.)
> ESS-help using r-project.org mailing list
More information about the ESS-help