Description Usage Arguments Details Value Examples
Summarise function complexity of a file or environment
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | sig_report(x, ...)
## Default S3 method:
sig_report(x, ...)
## S3 method for class 'environment'
sig_report(x, too_many_args = 10, too_many_lines = 50,
...)
## S3 method for class 'character'
sig_report(x, ...)
## S3 method for class 'sigreport'
print(x, ...)
|
x |
A path to an R file or an environment. |
... |
Passed to |
too_many_args |
Upper bound for a sensible number of args. |
too_many_lines |
Upper bound for a sensible number of lines. |
sig_report
summarises the number of input arguments and the
number of lines of each function in an environment of file, and
identifies problem files, in order to help you refactor your code.
If the input is a path to an R file, then that file is sourced into
a new environment and and the report is generated from that.
The number of lines of code that a function takes up is subjective
in R; this function uses length(deparse(fn))
.
An object of class “sigreport” with the elements.
n_varsNumber of variables.
n_fnsNumber of functions.
n_argsTable of the number of args of each function.
too_many_argsUpper bound for a sensible number of args.
fns_with_many_argsNames of each function with more args
than too_many_args
.
n_linesTable of the number of lines of each function body.
too_many_linesUpper bound for a sensible number of lines.
long_fnsNames of each function with more lines than
too_many_lines
.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | #Summarise function complexity in an environment
sig_report(pkg2env(stats))
#Summarise function complexity in a file
## Not run:
tmp <- tempfile(fileext = ".R")
writeLines(c(toString(sig(scan)), deparse(body(scan))), tmp)
sig_report(tmp)
## End(Not run)
# Adjust the cutoff for reporting
sig_report(
baseenv(),
too_many_args = 20,
too_many_lines = 100
)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.