trailing_blank_lines_style: Validation of Trailing Blank Lines

View source: R/trailing_blank_lines_style.R

trailing_blank_lines_styleR Documentation

Validation of Trailing Blank Lines

Description

Check that a script file does not contain superfluous trailing blank lines.

Usage

trailing_blank_lines_style(srcData)

Arguments

srcData

a list as returned by getSourceData.

Details

Good coding practices dictate that a script file should not end with blank lines.

Value

Boolean. When FALSE, a message indicates the nature of the error and the faulty lines, and the returned value has the following attributes:

lines

faulty line numbers;

message

text of the error message.

Examples

## Keep parse data in non interactive sessions.
if (!interactive())
    op <- options(keep.source = TRUE)

## Correct script without trailing blank lines
fil <- tempfile(fileext = ".R")
cat("## A simple function",
    "foo <- function(x, y)",
    "{",
    "    x + y",
    "}",
    file = fil, sep = "\n")
trailing_blank_lines_style(getSourceData(fil))

## Incorrect script with trailing blank lines
fil <- tempfile(fileext = ".R")
cat("## A simple function",
    "foo <- function(x, y)",
    "{",
    "    x + y",
    "}",
    "",
    "",
    file = fil, sep = "\n")
trailing_blank_lines_style(getSourceData(fil))

roger documentation built on Oct. 24, 2023, 9:07 a.m.