sig: Generate a function signature object

Description Usage Arguments Value Note Examples

Description

Generates a signature object for a function.

Usage

1
sig(fn, name_override)

Arguments

fn

A function.

name_override

Override the default function name. See examples.

Value

A list, with the elements

Note

Anonymous functions are given the name "..anonymous..".

Nonstandard names ("foo bar"), assignment fns ("foo<-"), operators (" in backquotes.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
sig(R.Version)               #no args
sig(scan)                    #lots of args
sig(function(x, y) {x + y})  #anonymous
sig(sum)                     #primitive
fn_list <- list(
  mean = mean,
  var = var
)
lapply(fn_list, sig)         #names are a mess
Map(                         #use Map for lists
  sig,
  fn_list,
  names(fn_list)             #Map mangles names, so override
)

Example output

R.Version <- function()
scan <- function(file = "", what = double(), nmax = -1, n = -1, sep = "", quote
    = if (identical(sep, "\n")) "" else "'\"", dec = ".", skip = 0, nlines = 0,
    na.strings = "NA", flush = FALSE, fill = FALSE, strip.white = FALSE, quiet
    = FALSE, blank.lines.skip = TRUE, multi.line = TRUE, comment.char = "",
    allowEscapes = FALSE, fileEncoding = "", encoding = "unknown", text,
    skipNul = FALSE)
..anonymous.. <- function(x, y)
sum <- function(..., na.rm = FALSE)
$mean
`X[[i]]` <- function(x, ...)

$var
`X[[i]]` <- function(x, y = NULL, na.rm = FALSE, use)

$mean
mean <- function(x, ...)

$var
var <- function(x, y = NULL, na.rm = FALSE, use)

sig documentation built on May 1, 2019, 8:45 p.m.

Related to sig in sig...