View source: R/ops_spaces_style.R
ops_spaces_style | R Documentation |
Check that spacing around infix and unary operators is valid.
ops_spaces_style(srcData, ops = ops_list)
srcData |
a list as returned by |
ops |
vector of R parser tokens corresponding to infix operators to check for correct spacing; see details. |
Good coding practices dictate to surround infix operators with spaces (including line breaks) and to follow unary operators immediately by their argument.
The default value for argument ops
is an internal object
containing the following R parser tokens: '+'
, '-'
,
'*'
, GT
, GE
, LT
, LE
,
EQ
, NE
, AND
, OR
, AND2
,
OR2
, '!'
, LEFT_ASSIGN
, RIGHT_ASSIGN
,
EQ_ASSIGN
, EQ_SUB
, IN
, SPECIAL
.
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. |
## Keep parse data in non interactive sessions.
if (!interactive())
op <- options(keep.source = TRUE)
## Correct use of spacing around '+' and '-' operators
fil <- tempfile(fileext = ".R")
cat("2 + 3",
"-2",
"(4\n + 2)",
"4 +\n2",
file = fil, sep = "\n")
ops_spaces_style(getSourceData(fil), c("'+'", "'-'"))
## Incorrect use of spacing around '>' and '!' operators
fil <- tempfile(fileext = ".R")
cat("2> 3",
"4 >2",
"6>3",
"! FALSE",
"!\nFALSE",
file = fil, sep = "\n")
ops_spaces_style(getSourceData(fil), c("GT", "'!'"))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.