curfnfinder: Function to find the name of the calling function

Description Usage Arguments Details Value Author(s) Examples

Description

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

Usage

1
2
3
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.

Author(s)

Nick Sabbe (Arteveldehogeschool)

Maintainer: Gjalt-Jorn Peters <gjalt-jorn@userfriendlyscience.com>

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
  functionA <- functionB <- function() {
    curFn <- curfnfinder();
    if (curFn == 'functionA') {
      cat('Doing something\n');
    } else {
      cat('Doing something else\n');
    }
    cat('Doing something generic.');
  }
  functionA();
  functionB();

Matherion/userfriendlyscience documentation built on May 7, 2019, 3:41 p.m.