Re: [R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
On second glance, while it works for 'stack', it doesn't appear to work for 'overlay': > overlay(sapply(obs,get)) Error in function (classes, fdef, mtable) : unable to find an inherited method for function "overlay", for signature "list", "missing" At this point, this may be more of a 'rast

Re: [R] Pass character vector to function argument

2010-11-16 Thread Henrique Dallazuanna
Using David's examples: do.call(stack, lapply(obs, get)) On Tue, Nov 16, 2010 at 4:04 PM, Kevin Ummel wrote: > Sorry, I shouldn't have used 'sum' as an example; I am looking for a > solution in the case of functions that do not result in simple vectors or > matrices. > > The "real-world" examp

Re: [R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
Thanks, David. That does, indeed, work. It didn't occur to me that a list would do the job as an argument. Thanks for the fix! kevin On Nov 16, 2010, at 6:58 PM, David Winsemius wrote: > > On Nov 16, 2010, at 1:04 PM, Kevin Ummel wrote: > >> Sorry, I shouldn't have used 'sum' as an example;

Re: [R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
Sorry, I shouldn't have used 'sum' as an example; I am looking for a solution in the case of functions that do not result in simple vectors or matrices. The "real-world" example is something like the following using the 'raster' package, though (I think) any command producing an S4 object could

Re: [R] Pass character vector to function argument

2010-11-16 Thread David Winsemius
On Nov 16, 2010, at 1:04 PM, Kevin Ummel wrote: Sorry, I shouldn't have used 'sum' as an example; I am looking for a solution in the case of functions that do not result in simple vectors or matrices. The "real-world" example is something like the following using the 'raster' package, th

Re: [R] Pass character vector to function argument

2010-11-16 Thread Ivan Calandra
Hi, It would have been nice to see what you've tried. Here is what I got (maybe not the easiest, but looks like it works) a1 <- 1 a2 <- 2 obs <- objects(pattern=glob2rx("a?")) sum(unlist(mget(obs, envir=.GlobalEnv))) [1] 3 It also works with vectors: a1 <- 1:10 a2 <- 11:20 sum(unlist(mget(obs,

Re: [R] Pass character vector to function argument

2010-11-16 Thread David Winsemius
On Nov 16, 2010, at 10:34 AM, Kevin Ummel wrote: A bit embarrassed to post this seemingly trivial question, but I can't find anything in the archive that's quite relevant: a1=1 a2=2 obs=objects(pattern=glob2rx("a?")) I want to utilize 'obs' as a function argument to produce something lik

[R] Pass character vector to function argument

2010-11-16 Thread Kevin Ummel
A bit embarrassed to post this seemingly trivial question, but I can't find anything in the archive that's quite relevant: a1=1 a2=2 obs=objects(pattern=glob2rx("a?")) I want to utilize 'obs' as a function argument to produce something like: sum(a1,a2) Obviously, sum(obs) doesn't work, but I'