[R] naming an operation inside a function

Thomas W Blackwell tblackw at umich.edu
Tue Apr 8 14:47:35 CEST 2003

I don't understand what it would mean to "name" a specific
operation inside a function, so that you could "call it"
later on.

It's perfectly possible to define and use one function
inside the scope of another.  E.g.

conditional.plot <- function(cond, ...)
   {  if (cond[1]) plot(...) else hist(...)  }

(Poorly designed example, since it depends on having
named arguments "x" or "x" and "y" in ... for correct
execution of the plotting commands, and, in its present
form, doesn't use that as part of the condition ... but.)

Ah, with this example I can see that one reason why you
might want to do this is if you want the side effects of
function.a or function.b, such as a plot, rather than
their return values.

-  tom blackwell  -  u michigan medical school  -  ann arbor  -

On Mon, 7 Apr 2003, [iso-8859-1] Dave Caccace wrote:

>  Thank you for you previous help :)
> I now need ot know how i can name a specific operation
> inside a function. i am using the if(cond){}else{}
> construction and would like to name it. However if i
> do assign a name to it and then call it later onm in
> the function, it is not recognised. does any one have
> any idea why?
> Thank you,
> Dave

More information about the R-help mailing list