I could not find the all.names function in R so I created the enclosed. Comments, criticisms, or changes to a one-liner by creating nested anonymous functions are welcome. I'll try to work out a corresponding all.vars function. ### $Id: allFns.R,v 1.2 1997/04/28 13:08:21 bates Exp $ ### Some replacement functions that are missing in R ### Determine all the names (symbols) occuring in an object. ### This is probably grossly inefficient. all.names <- function (x) { if (mode(x) == "symbol") return(as.character(x)) if (length(x) == 0) return(NULL) if (is.recursive(x)) return(unlist(lapply(as.list(x), all.names))) character(0) } ### Local variables: ### mode: R ### End: =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-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 =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Martin Maechler
1997-Apr-28 15:07 UTC
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 at stat.math.ethz.ch =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
Seemingly Similar Threads
- Alternating numbers in rep()
- going from 1.4.21 to 1.6 beta 9
- Re: (PR#1210) an error message from scan() surprised vograno@arbitrade.com.
- Upstream and downstream (was Re: What are the differences between systemd and non-systemd Linux distros?)
- Sum of Numeric Values in a DF Column