Re: [R] Extract the names of the arguments in an "expression"

2011-03-24 Thread Duncan Murdoch
An improvement on my suggestion using codetools is to use codetools::findGlobals(f, merge=FALSE) which separates the functions and variables: $functions [1] "*" "cos" $variables [1] "omega" "rho" This is important, because R distinguishes between functions and variables by usage when it is

Re: [R] Extract the names of the arguments in an "expression"

2011-03-24 Thread Gabor Grothendieck
2011/3/24 Javier López-de-Lacalle : > Hi everybody: > > I need to get the names of the arguments in an object of class "expression". > I've got the following expression: > >> x <- expression(rho * cos(omega)) > > Is there any function or procedure that returns the names of the arguments > (in the e

Re: [R] Extract the names of the arguments in an "expression"

2011-03-24 Thread Kenn Konstabel
I tried this as an exercise and here's what I arrived to: collector <- function(expr){ RES <- list() foo <- function(x) unlist(lapply(x, as.list)) EXPR <- foo(expr) while(length(EXPR) >0){ if(is.symbol(EXPR[[1]])){ RES <- c(RES, EXPR[[1]]) EXPR <- EXPR[-1

Re: [R] Extract the names of the arguments in an "expression"

2011-03-24 Thread Duncan Murdoch
On 11-03-24 5:03 AM, Javier López-de-Lacalle wrote: Hi everybody: I need to get the names of the arguments in an object of class "expression". I've got the following expression: x<- expression(rho * cos(omega)) Is there any function or procedure that returns the names of the arguments (in th

[R] Extract the names of the arguments in an "expression"

2011-03-24 Thread Javier López-de-Lacalle
Hi everybody: I need to get the names of the arguments in an object of class "expression". I've got the following expression: > x <- expression(rho * cos(omega)) Is there any function or procedure that returns the names of the arguments (in the example: "rho" and "omega")? I tried a rough appro