Re: [R] function call

From: Gabor Grothendieck <>
Date: Mon 19 Jun 2006 - 21:54:14 EST

Perhaps you what you want to do is to return an object that has a print method like this:

f1 <- function(x) structure(c(x, x^2), class = "f1") print.f1 <- function(x) cat("x is", x[1], "x squared is", x[2], "\n")

Now you could do this:

f1(3) # gives fancy output
y <- f1(3) # returns structure
unclass(y) # y, not as an "f1" class object

The point is that print.f1 could return something which is different than the output of f1.

On 6/19/06, <> wrote:
> Dear R-users,
> When a function f1() is called, is there a way to know,
> from inside the function f1(), if f1() is directly called from the
> R console, or indirectly from another function f2() ?
> Of course, I may add an argument to f1(..., callbyf2=FALSE) only used
> by f2() giving explicitely this info, but I would like to know
> if there may be a more generic way ?
> Thanks for any info or pointer
> ______________________________________________
> mailing list
> PLEASE do read the posting guide!
> mailing list PLEASE do read the posting guide! Received on Mon Jun 19 22:11:52 2006

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 20 Jun 2006 - 04:11:41 EST.

Mailing list information is available at Please read the posting guide before posting to the list.