Skip to content
Prev 106561 / 398513 Next

how to 'get' an object that is part of a list

Thank you Gabor.  Very interesting solution.
If I get it right, the first argument in function f is just a placeholder to
help extract the right element out of the list(...) that is passed to
length.  Very smart trick.

Jim's solution appears a bit simpler, at least along the lines that I was
thinking:

my.length <- function(...) {
	names <- as.character(substitute(list(...)))[-1]
	sapply(names, function(x){y <- eval(parse(text=x)); length(y)})
} 

-Christos

-----Original Message-----
From: Gabor Grothendieck [mailto:ggrothendieck at gmail.com] 
Sent: Sunday, December 24, 2006 7:41 AM
To: jim holtman
Cc: christos at nuverabio.com; 
Subject: Re: [R] how to 'get' an object that is part of a list

Is this what you are looking for:
+    f <- function(nm, val) length(val)
+    mapply(f, make.names(as.list(match.call()[-1])), list(...)) }
xx xx.b
   2    5
On 12/24/06, jim holtman <jholtman at gmail.com> wrote: