curfnfinder

This function finds and returns the name of the function calling it. This can be useful, for example, when generating functions algorithmically.

Keywords
utility
Usage
curfnfinder(skipframes = 0, skipnames = "(FUN)|(.+apply)|(replicate)",
            retIfNone = "Not in function", retStack = FALSE,
            extraPrefPerLevel = "\t")
Arguments
skipframes
Number of frames to skip; useful when called from an anonymous function.
skipnames
A regular expression specifying which substrings to delete.
retIfNone
What to return when called from outside a function.
retStack
Whether to return the entire stack or just one function.
extraPrefPerLevel
Extra prefixes to return for each level of the function.
Details

This function was written by Nick Sabbe for his package addendum. He posted it on Stack Exchange at http://stackoverflow.com/questions/7307987/logging-current-function-name and I included this here with this permission.

Value

The current function.

Aliases
  • curfnfinder
Examples
  functionA <- functionB <- function() {
    curFn <- curfnfinder();
    if (curFn == 'functionA') {
      cat('Doing something\n');
    } else {
      cat('Doing something else\n');
    }
    cat('Doing something generic.');
  }
  functionA();
  functionB();
Documentation reproduced from package userfriendlyscience, version 0.6-1, License: GPL (>= 2)

Community examples

Looks like there are no examples yet.