Re: [R] Referencing function name from within function

From: jim holtman <jholtman_at_gmail.com>
Date: Tue 03 Apr 2007 - 11:41:17 GMT

Try this:

> myfunction <- function(){

+     # some calculations
+     # now get my name
+     .caller <- sys.call()
+     cat(paste(as.character(.caller[[length(.caller)]]),"needs 'xyz'\n"))
+ }

> myfunction()

myfunction needs 'xyz'
>
>

On 4/3/07, Johannes Graumann <johannes_graumann@web.de> wrote:
>
> Hello,
>
> For verbose coding I'd like to do something like:
> > myfunction <- function(x){
> > if (a){
> > stop(paste(myfunction_name_here,"requires xyz!")
> > }
> Is that possible?
>
> Thanks for any hints, Joh
>
> ______________________________________________
> R-help@stat.math.ethz.ch 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.
>

-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?

	[[alternative HTML version deleted]]

______________________________________________
R-help@stat.math.ethz.ch 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.
Received on Tue Apr 03 21:48:07 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 03 Apr 2007 - 14:30:54 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.