unneeded_concatenation_style {roger}R Documentation

Validation of Concatenation Usage

Description

Check that function c is used with more than one argument.

Usage

unneeded_concatenation_style(srcData)

Arguments

srcData

a list as returned by getSourceData.

Details

Function c is used to combine its arguments. Therefore, good coding practice dictates that the function should never be used with zero or one argument.

Usage with zero argument to create an empty vector should be replaced by calls to object creation functions like numeric or character.

Usage with one argument is a superfluous call to c that should just be replaced by the argument.

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 the 'c()' function
fil <- tempfile(fileext = ".R")
cat("x <- c(1, 2, 3, 4)", file = fil)
unneeded_concatenation_style(getSourceData(fil))

## Incorrect uses of the 'c()' function
fil <- tempfile(fileext = ".R")
cat("x <- c()",
    "x <- c(42)",
    file = fil, sep = "\n")
unneeded_concatenation_style(getSourceData(fil))

[Package roger version 1.5-1 Index]