commas_style {roger}R Documentation

Validation of Spacing Around Commas

Description

Check that commas are never preceded by a space, unless the previous symbol is also a comma, and always followed by one, unless the comma ends the line.

Usage

commas_style(srcData)

Arguments

srcData

a list as returned by getSourceData.

Details

Good coding practices dictate to follow commas by a space, unless it ends its line, and to never put a space before. An exception to the latter rule is consecutive commas, as in indexing of arrays.

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 use of spacing around a comma
fil <- tempfile(fileext = ".R")
cat("x <- c(2, 3, 5)", "crossprod(2,", "x)",
    "a <- array(1:24, 2:4)", "a[1, , ]",
    file = fil, sep = "\n")
commas_style(getSourceData(fil))

## Incorrect use of spacing around a comma
fil <- tempfile(fileext = ".R")
cat("x <- c(2,3, 5)", "crossprod(2 ,", "x)",
    "a <- array(1:24, 2:4)", "a[1,, ]",
    file = fil, sep = "\n")
commas_style(getSourceData(fil))

[Package roger version 1.5-1 Index]