knitr (version 1.16)

wrap_rmd: Wrap long lines in Rmd files

Description

This function wraps long paragraphs in an R Markdown file. Other elements are not wrapped: the YAML preamble, fenced code blocks, section headers and indented elements. The main reason for wrapping long lines is to make it easier to review differences in version control.

Usage

wrap_rmd(file, width = 80, text = NULL, backup)

Arguments

file

the input Rmd file

width

the expected line width

text

an alternative to file to input the text lines

backup

the path to back up the original file (in case anything goes wrong); if NULL, it is ignored; by default it is constructed from file by adding __ before the base filename

Value

If file is provided, it is overwritten; if text is provided, a character vector is returned.

Examples

Run this code
# NOT RUN {
wrap_rmd(text = c("```", "1+1", "```", "- a list item", "> a quote", "", 
    paste(rep("this is a normal paragraph", 5), collapse = " ")))
# }

Run the code above in your browser using DataCamp Workspace