sig_report {sig}R Documentation

Summarise function complexity of a file or environment

Description

Summarise function complexity of a file or environment

Usage

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,
  length_metric = c("deparse", "body"),
  ...
)

## S3 method for class 'character'
sig_report(x, ...)

## S3 method for class 'sigreport'
print(x, ...)

Arguments

x

A path to an R file or an environment.

...

Passed to sig_report.environment.

too_many_args

Upper bound for a sensible number of args.

too_many_lines

Upper bound for a sensible number of lines.

length_metric

Either "deparse" or "body". See note.

Details

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 gives you a choice of length(deparse(fn)) or length(body(fn)), depending upon the value of length_metric. The body metric tends to give smaller values than deparse, so you may want to reduce the too_many_lines argument.

Value

An object of class “sigreport” with the elements:

Examples

#Summarize function complexity in an environment
sig_report(pkg2env(stats))    
#Summarize function complexity in a file

# From a file
tmp <- tempfile(fileext = ".R")
dump("scan", tmp)
sig_report(tmp)
   
# From an environment, adjusting the cutoff for reporting
sig_report(              
  baseenv(),  
  too_many_args  = 20,    
  too_many_lines = 100
)      
# Alternate length metric          
sig_report(baseenv(), length_metric = "body")

[Package sig version 0.0-6 Index]