line_length_style {roger} | R Documentation |
Validation of Length of Code and Comments Lines
Description
Check that the length of code and comment lines does not exceed a given limit in number of characters.
Usage
line_length_style(srcData, nchar_max = 80L)
Arguments
srcData |
a list as returned by |
nchar_max |
maximum number of characters per line. |
Details
Good coding practice dictates to limit line length to a value around 80 characters for readability purposes.
The line length is determined from the column number ending each line
of code in the parse information. This may give unintended results if
the encoding used in getParseData
does not match the
encoding of the script file and the latter contains non ASCII
characters.
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)
## Valid line length
fil <- tempfile(fileext = ".R")
cat("## innocuous comment",
"x <- 2",
"y <- 3",
"x + y",
file = fil, sep = "\n")
line_length_style(getSourceData(fil))
## Limit valid line length to only 20 characters
fil <- tempfile(fileext = ".R")
cat("## no longer innocuous comment",
"x <- 2",
"y <- 3",
"x + y",
file = fil, sep = "\n")
line_length_style(getSourceData(fil), 20)
[Package roger version 1.5-1 Index]