assignment_style {roger}R Documentation

Validation of the Assignment Operator

Description

Check that the left assign symbol (<-) is used to assign values to objects instead of the equation assign symbol (=).

Usage

assignment_style(srcData)

Arguments

srcData

a list as returned by getSourceData.

Details

Although = is a proper assignment symbol at the top-level, its use is discouraged in R. Good coding practices dictate to rather use <- for (left) assignment to objects.

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 coding practice
fil <- tempfile(fileext = ".R")
cat("x <- 2", file = fil, sep = "\n")
assignment_style(getSourceData(fil))

## Incorrect coding practice
cat("x = 2", file = fil, sep = "\n")
assignment_style(getSourceData(fil))

[Package roger version 1.5-1 Index]