Look for all R scripts under a directory (using the pattern
"[.][RrSsQq]$"), then tidy them with tidy_source(). If
successful, the original scripts will be overwritten with reformatted ones.
Please back up the original directory first if you do not fully understand
the tricks used by tidy_source(). tidy_file() formats
scripts specified by file names.
tidy_dir(path = ".", recursive = FALSE, ...)
tidy_file(file, ...)The path to a directory containning R scripts.
Whether to recursively look for R scripts under path.
Other arguments to be passed to tidy_source().
A vector of filenames.
Invisible NULL.
library(formatR)
path = tempdir()
file.copy(system.file("demo", package = "base"), path, recursive = TRUE)
#> [1] TRUE
tidy_dir(path, recursive = TRUE)
#> tidying /tmp/RtmpJD4itr/demo/error.catching.R
#> tidying /tmp/RtmpJD4itr/demo/is.things.R
#> tidying /tmp/RtmpJD4itr/demo/recursion.R
#> tidying /tmp/RtmpJD4itr/demo/scoping.R