R-beta: 'all.names' function -- failing as.list( _function_ )

Martin Maechler maechler at stat.math.ethz.ch
Mon Apr 28 17:07:05 CEST 1997


your 'all.names' function
	[wow, I didn't even know it in S..]
seems to have been written with S in your mind;
you are exactly demonstrating some of the 'fine' differences between  R & S

>1> all.names <- function (x) 
>2> {
>3>   if (mode(x) == "symbol")  return(as.character(x))
>4>   if (length(x) == 0)       return(NULL)
>5>   if (is.recursive(x))      return(unlist(lapply(as.list(x), all.names)))
>6>   character(0)
>7> }   

1) length(x) is not always defined in R; e.g. it is NOT for functions.
   --> Delete line 4  

2) functions  are NOT lists and cannot be coerced to,
   which makes line 5 fail for function objects.

As a matter of fact, I once was also a bit interested in this.
At that time, 'args' did not yet exist, and I wanted to abuse 'as.list' for
I was told that this is 'bad'
	(functions have nothing to do with lists;
	 in R, functions can have a defining environment going with them...)
and 'args' is now provided which helps my most immediate need.

In short: I don't think  you can define an  all.names(.) function which
	  works with functions arguments, in the current version of R.

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list