sig: Generate a function signature object

View source: R/sig.R

sigR Documentation

Generate a function signature object

Description

Generates a signature object for a function.

Usage

sig(fn, name_override, ...)

## Default S3 method:
sig(fn, ...)

## S3 method for class 'character'
sig(fn, ...)

## S3 method for class 'call'
sig(fn, ...)

## S3 method for class 'formula'
sig(fn, ...)

## S3 method for class 'name'
sig(fn, ...)

Arguments

fn

A function.

name_override

Override the default function name. See examples.

...

For possible additional future arguments, currently unused.

Value

A list, with the elements

  • nameThe name of the function.

  • argsThe arguments of the function.

Note

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

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

Examples

sig(R.Version)               #no args
sig(scan)                    #lots of args
sig(function(x, y) {x + y})  #anonymous
sig(sum)                     #primitive

sig("sd")                   #string input
sig("function(x, y) {x + y}")
sig(~ prod)                 #formula input
sig(~ function(x, y) {x + y})
sig(quote(paste0))          #name input
sig(quote(function(x, y) {x + y}))

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
)            

sig documentation built on April 21, 2022, 5:07 p.m.

Related to sig in sig...