1

Is there a way to reformat all code chunks in an Rmarkdown document?

I have Rmarkdown documents which need code reformatting but I can't select all and use the Rstudio reformat code.

Ricecakes
  • 681
  • 1
  • 5
  • 13

1 Answers1

1

The package styler can reformat Rmarkdown files.

library(styler)
style_file("badlyFormattedFile.Rmd")

It can also reformat all Rmd or R scripts in a directory using

style_dir("directoryWithUglyFiles")
Ricecakes
  • 681
  • 1
  • 5
  • 13