reformat_code: Format the code in the usage and examples sections

View source: R/build.R

reformat_codeR Documentation

Format the code in the usage and examples sections

Description

The function tidy_source in the formatR package is used to polish the Rd files generated by roxygen2 in the usage and examples sections.

Usage

reformat_code(path, ...)

Arguments

path

the path of the Rd file

...

other arguments passed to tidy_source

Value

NULL; as a side effect, the original Rd file will be updated

Note

If the usage or examples code is not syntactically correct, it will not be reformatted and a message will be printed on screen. One possible situation is the percent symbol %, which should be escaped even in the examples code (cf Writing R Extensions), and this can make the code syntactically incorrect, e.g. a %in% b should be a \%in\% b but the latter is not valid R code. Anyway, this function will try to unescape the percent symbols before reformating the code, then escape them.

Author(s)

Yihui Xie <http://yihui.org>

See Also

tidy_source

Examples

rd.file = system.file("examples", "reformat_code_demo.Rd", package = "Rd2roxygen")
file.copy(rd.file, tempdir())
fmt.file = file.path(tempdir(), "reformat_code_demo.Rd")

file.show(fmt.file)  ## show the raw Rd

reformat_code(fmt.file)
file.show(fmt.file)  ## the formatted Rd

yihui/Rd2roxygen documentation built on April 16, 2024, 8:26 a.m.