[R] How to get the function names

Jerome Asselin jerome.asselin at crchum.qc.ca
Thu Oct 5 23:07:05 CEST 2006


On Thu, 2006-10-05 at 22:41 +0200, Søren Højsgaard wrote:
> I've defined the function
>  
> getFunNames <- function(FUN){
>   if (!is.list(FUN)) 
>     fun.names <- paste(deparse(substitute(FUN)), collapse = " ")
>   else
>     fun.names <- unlist(lapply(substitute(FUN)[-1], function(a) paste(a)))
>   fun.names
> }

Hi,

Try this:
> getFunNames <- function(x)
+   sapply(as.list(sys.call()[[2]][-1]),as.character)
> getFunNames(c(mean,ff))
[1] "mean" "ff"
> foo <- function() getFunNames(c(mean,ff))
> foo()
[1] "mean" "ff"

HTH,
Jerome

-- 
Jerome Asselin, M.Sc., Agent de recherche, RHCE
CHUM -- Centre de recherche
3875 rue St-Urbain, 3e etage // Montreal QC  H2W 1V1
Tel.: 514-890-8000 Poste 15914; Fax: 514-412-7106



More information about the R-help mailing list