sig v0.0-5

0

Monthly downloads

0th

Percentile

Print Function Signatures

Print function signatures and find overly complicated code.

Readme

sig prints R functions signatures and writes them to file. (In this case, signature means the name and arguments, with possible defaults, of that function.)

To load the package, type

library(sig)

If you want to know how to call a function, just pass a function to the sig function. For example,

sig(mean)
#mean <- function(x, ...)
sig(mean.default)
#mean.default <- function(x, trim = 0, na.rm = FALSE, ...)

If you pass an anonymous function, it is given the name ..anonymous...

sig(function(x, y) {x + y})
#..anonymous.. <- function(x, y)

You can override the name of the function by passing a second argument. This is useful when using sig with an *apply function.

fn_list <- list(
  mean = mean, 
  var = var
)
lapply(fn_list, sig)         #names are a mess
mapply(                      #use mapply for lists
  sig, 
  fn_list, 
  names(fn_list), 
  SIMPLIFY = FALSE
)

"Black Box" is a useful game for testing how maintainable your code is. You give your friend or colleague the signatures of your functions and have them guess what the function contents. For example, if you show them

mean <- function(x, ...)

then they might be able to guess that the function calculates the arithmetic mean of a numeric input.

If you didn't know what it was, the signature for the lm function doesn't make it as clear what the function does

sig(lm)
#lm <- function(formula, data, subset, weights, na.action, method =
#  "qr", model = TRUE, x = FALSE, y = FALSE, qr = TRUE, singular.ok =
#  TRUE, contrasts = NULL, offset, ...)

Your friend might guess that since the function takes a formula and a data arguement that it is some kind of model. Some of the other arguments may be guessable. "Oh, weights must let you run a weighted model!" Beyond that, the function's purpose is difficult to determine without consulting documentation.

In general, if you can guess what a function does, and what its body should contain, based only on the signature, then that function will be easy to use and easy to maintain. By contrast, an unclear function signature provides a warning that it may be difficult to use or maintain.

To make Black Box easy to play, use the write_sigs function to write all the functions from a file or R package to a text file.

#From an environment
write_sigs(
  pkg2env(graphics), 
  "graphics pkg sigs.R"
)

#From a file
write_sigs(
  "my R file.R",
  "my sigs.R
)

Functions in sig

Name Description
as.siglist Coerce object to be a siglist
exponential_cut Cut with exponential breaks
print_engine Workhorse of the print methods
is.siglist Is the input a siglist?
list_sigs List the signatures of all functions
sig_report Summarise function complexity of a file or environment
fix_fn_names Fix names for sigs
source_to_new_env Source a file into a new environment.
[ Indexing for siglists
toString.siglist Print a siglist object
sig Generate a function signature object
toString.sig Print a sig object
as.sig Coerce object to be a sig
is.sig Is the input a sig?
backquote Wrap in backquotes
write_sigs Write sigs to file
pkg2env Get environment of a package.
as.list.sig Convert to list
No Results!

Last month downloads

Details

Type Package
Date 2014-01-19
License Unlimited
LazyLoad yes
LazyData yes
Acknowledgments Development of this package was partially funded by the Proteomics Core at Weill Cornell Medical College in Qatar . The Core is supported by 'Biomedical Research Program' funds, a program funded by Qatar Foundation.
Collate 'sig.R' 'list_sigs.R' 'as.R' 'is.R' 'sig_report.R' 'indexing.R' 'utils.R' 'write_sigs.R'
Packaged 2015-01-20 11:57:12 UTC; rjc2003
NeedsCompilation no
Repository CRAN
Date/Publication 2015-01-22 00:45:46

Include our badge in your README

[![Rdoc](http://www.rdocumentation.org/badges/version/sig)](http://www.rdocumentation.org/packages/sig)