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

Martin Maechler (maechler@stat.math.ethz.ch)
Mon, 28 Apr 97 17:07:05 +0200


Date: Mon, 28 Apr 97 17:07:05 +0200
Message-Id: <9704281507.AA00504@>
From: Martin Maechler <maechler@stat.math.ethz.ch>
To: bates@stat.wisc.edu
In-Reply-To: <m0wLqDf-000hhBC@franz.stat.wisc.edu> (message from Douglas Bates
Subject: Re: R-beta: 'all.names' function -- failing   as.list( _function_ )

Doug,

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
functions.
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@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=