Hello,
Is there a way to get the name of the function currently running?
I'd like to have something like this
x <- function(){
myName <- getNameOfCurrentFunction
cat(myName)
}
so that
x()
would result in
"x"
Thanks for any pointers,
Joh
How to get name of current function?
3 messages · Brian Ripley, Johannes Graumann
On Tue, 20 Jan 2009, Johannes Graumann wrote:
Hello, Is there a way to get the name of the function currently running?
It may not even have a name (you can write functions anonymously as 'function(x) x+1' in function arguments). I think rather the point is that you can get the name (if any) of the current call (and f1 and f2 may be two names for the same function). You can use match.call() or the sys* functions to help you. x <- function() match.call()[[1]] would probably be enough for your purposes.
I'd like to have something like this
x <- function(){
myName <- getNameOfCurrentFunction
cat(myName)
}
so that
x()
would result in
"x"
Thanks for any pointers,
Joh
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595
Thanks a lot. Exactly what I was looking for. Joh
Prof Brian Ripley wrote:
On Tue, 20 Jan 2009, Johannes Graumann wrote:
Hello, Is there a way to get the name of the function currently running?
It may not even have a name (you can write functions anonymously as 'function(x) x+1' in function arguments). I think rather the point is that you can get the name (if any) of the current call (and f1 and f2 may be two names for the same function). You can use match.call() or the sys* functions to help you. x <- function() match.call()[[1]] would probably be enough for your purposes.
I'd like to have something like this
x <- function(){
myName <- getNameOfCurrentFunction
cat(myName)
}
so that
x()
would result in
"x"
Thanks for any pointers,
Joh