Search code examples
r-markdownformatr

Is there a way of reformatting all code chunks in an Rmarkdown document?


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.


Solution

  • 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")