Within a function I'd often like to obtain a text string equal to the name of
the function.
One use for this: To generate a filename for use in pdf(). This enables me to
keep track of which function generated a particular graphic came.
match.call() puts parentheses at the end of the name. I don't want parentheses
in a filename.
The following kludgey function gives the desired result.
JANK
function(x, y) {
one<-deparse(match.call())
functionName<-gsub("\\(.*", "", one, perl=T)
cat("The name of this function is ", functionName, "\n")
}
JANK(55, pi^2)
The name of this function is JANK
JANK()
The name of this function is JANK
Is there not a more direct way? To paraphrase Douglas Bates, the above approach is like
the diner scene in the movie "Five Easy Pieces". You get an order of toast by
first ordering a chicken sandwich and then telling the waitress to hold (that is, to
subtract) the meat, lettuce, and mayonnaise.
Thanks for any insights
Jacob Wegelin
______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.