Learn R Programming

roger (version 1.5-1)

trailing_whitespace_style: Validation of Trailing Whitespace

Description

Check that a script file does not contain unnecessary whitespace at the end of lines.

Usage

trailing_whitespace_style(srcData)

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.

Arguments

srcData

a list as returned by getSourceData.

Details

Good coding practices dictate that a script file should contain unnecessary whitespace (space or tabulation) at the end of lines.

Examples

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

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

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

Run the code above in your browser using DataLab