Description Usage Arguments Details Value See Also Examples
Check certain aspects of the format of R code files in
the ‘R’ subdirectory of a package, or of any other
kinds of files. R code can also be extracted from Sweave
files. Optionally write descriptions of problems to the
logfile used by pkgutils, which can be set using
logfile
. Alternatively, check the labels used in
the lines that start a Sweave code chunk.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | check_R_code(x, ...)
## S3 method for class 'character'
check_R_code(x, lwd = 80L,
indention = 2L, roxygen.space = 1L, comma = TRUE,
ops = TRUE, parens = TRUE, assign = TRUE,
modify = FALSE, ignore = NULL, accept.tabs = FALSE,
three.dots = TRUE, what = "R", encoding = "",
filter = c("none", "sweave", "roxygen"), ...)
check_Sweave_start(x, ...)
## S3 method for class 'character'
check_Sweave_start(x, ignore = TRUE,
what = c("vignettes", file.path("inst", "doc")),
encoding = "", ...)
logfile(x)
## S3 method for class 'NULL'
logfile(x)
## S3 method for class 'character'
logfile(x)
|
x |
For For |
lwd |
Numeric scalar. Maximum line width allowed. Set this to a reasonably large number to effectively turn checking off. |
indention |
Numeric scalar. Number of spaces used for one unit of indention. Set this to 1 to effectively turn checking off. |
roxygen.space |
Numeric scalar. Number of spaces expected after roxygen2 comments (which start with ‘#’ followed by a single quote). |
comma |
Logical scalar indicating whether it should be checked that each comma is not preceded by a space but followed by a space. |
ops |
Logical scalar indicating whether it should be checked that operators are surrounded by spaces. |
parens |
Logical scalar indicating whether it should be checked that control-flow constructs are not directly followed by parentheses, that opening parentheses (and brackets) are not followed by a space, and that closing parentheses (and brackets) are followed by appropriate characters only and are not preceded by a space. |
assign |
Logical scalar indicating that it should be checked that there is no line break within named function-argument assignments. |
modify |
Logical scalar indicating whether the
source code should be modified (non-destructively, of
course) and input files overwritten (if changes were
possible). The modifications currently only comprise the
removal of whitespace from the ends of the lines and
optionally the replacement of each tabulator by
|
accept.tabs |
Logical scalar indicating whether tabulators are accepted. |
three.dots |
Logical scalar indicating whether
|
what |
Character vector naming the subdirectories to
consider; passed to |
encoding |
Character scalar passed as
‘.encoding’ argument to |
ignore |
Passed to |
filter |
Character scalar indicating the filter to
use. The |
... |
Optional other arguments passed to
|
check_R_code
is intended to ensure a consistent
and readable R coding style. Not all problems can be
checked, however. For instance, +
and -
are
binary as well as unary operators and should either be
followed by spaces or not, respectively. Yielding no
problem messages is thus just a minimum requirement for a
good coding style. For instance, indentation checking
does not check whether continuation lines have
the correct number of leading spaces. Rather, checks are
made line-per-line throughout. In addition to such false
negatives, check_R_code
falsely complains about
numbers in exponential notation.
Functions such as check_keywords
print
detected problems, if any, using message
. These
character vectors can also be saved by appending to a
logfile.
check_R_code
yields a logical vector; see
map_files
for details. Here the result is
returned invisibly. As a side effect, problem messages
are printed to stderr
. See logfile
for how to send these messages to a file.
logfile
returns a character scalar with the name
of the current logfile.
Other package-functions: copy_pkg_files
,
delete_o_files
,
is_pkg_dir
,
pack_desc
,
pkg_files
,
run_R_CMD
,
swap_code
,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | # Checking the R scripts that come with the package
(scripts <- pkg_files("pkgutils", "scripts"))
if (length(scripts)) {
result <- check_R_code(scripts) # should not yield any messages
stopifnot(is.logical(result), names(result) == names(scripts))
} else {
warning("scripts not found")
}
# See also the 'docu.R' script provided with this package, options
# '--blank', '--jspaces', '--width', '--assignoff', '--commaoff',
# '--opsoff', '--modify', '--good', '--parensoff', '--Rcheck', '--tabs' and
# '--untidy'. Checking can be turned off generally or specifically.
## logfile()
old <- logfile()
new <- tempfile()
logfile(new)
stopifnot(new == logfile())
logfile(old)
stopifnot(old == logfile())
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.