View source: R/line_length_style.R
line_length_style | R Documentation |
Check that the length of code and comment lines does not exceed a given limit in number of characters.
line_length_style(srcData, nchar_max = 80L)
srcData |
a list as returned by |
nchar_max |
maximum number of characters per line. |
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.
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)
## 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)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.