# [R] sub question

Peter Dalgaard p.dalgaard at biostat.ku.dk
Tue Feb 3 16:38:59 CET 2009

```Wacek Kusnierczyk wrote:

>>
>> (a) do not descend recursively into the function part (first element)
>> of a call
>> (b) do descend, unless it is a name
>
> if it is a name, how would you descend?

By calling a recursive function which has it as the argument. It's not a
problem unless you want it to be (first you descend into the first
element on a call, then realize that it is a name). There are
essentially three possibilities (cutting some red tape):

> f <- function(e) if (is.name(e))
print(e) else if(is.call(e)) invisible(lapply(e,f))
> f(~ fo(o)())
`~`
fo
o

> f <- function(e) if (is.name(e))
print(e) else if(is.call(e)) invisible(lapply(e[-1],f))
> f(~ fo(o)())

> f <- function(e) if (is.name(e)) print(e) else
if(is.call(e)) invisible( if(is.name(e[[1]]))
lapply(e[-1],f) else lapply(e,f))
> f(~ fo(o)())
o

The first two are essentially the current all.names and all.vars. The
third is the one that you seem to expect. Notice that it gets rather
more complicated than the others.

> one legitimate reason is to keep the syntax/semantics clean (worship the
> god of boring pedantry).
> be this not enough, a practical example could certainly be found, though

But can you be sure that there is no legitimate reason for expecting the
current behaviour?

--
O__  ---- Peter Dalgaard             Øster Farimagsgade 5, Entr.B
c/ /'_ --- Dept. of Biostatistics     PO Box 2099, 1014 Cph. K
(*) \(*) -- University of Copenhagen   Denmark      Ph:  (+45) 35327918
~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk)              FAX: (+45) 35327907

```