[R] do.call without arguments?

2007-11-05 Thread Antje
Hello,

I have a vector containing strings of simple operation methods.

methods <- c("mean","sd","median")e.g.

Now, I'd like to apply these methods to my data and I thought, I could make a 
do.call. But these methods don't need any further arguments... Do I have to 
create an empty argument list?

I wanted to use a tapply( data, factor, ??? do.call ??? )

Can anybody help how to solve this problem?

Antje

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] do.call and plotting functions ...

2008-11-19 Thread Roberto Brunelli
I'm trying to write a simple wrapper for plotting functions to make
them print to postscript, something like

ploteps <- function(file, plotFunction, ...) {

  args <- list(bquote(...))

 # prepare postscript device

 do.call(plot, args)

 # close postscript device
}

I have inserted the bquote otherwise I get a lot of numbers in the
plot when I plot/hist something. But if I invoke the function as

ploteps("foo.eps", hist, xlab = "X")

I get

Error in bquote(...) : unused argument(s) (xlab = "X")

What am I messing up?


Thanks a lot,

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] do.call without arguments?

2007-11-05 Thread Peter Dalgaard
Antje wrote:
> Hello,
>
> I have a vector containing strings of simple operation methods.
>
> methods <- c("mean","sd","median")e.g.
>
> Now, I'd like to apply these methods to my data and I thought, I could make a 
> do.call. But these methods don't need any further arguments... Do I have to 
> create an empty argument list?
>
> I wanted to use a tapply( data, factor, ??? do.call ??? )
>
> Can anybody help how to solve this problem?
>
>   
Not sure what you mean by "any further arguments", but I wouldn't use
do.call here:

> names(methods)<-methods
> with(airquality,
+  lapply(methods, function(f) tapply(Ozone,Month,FUN=f, na.rm=T)))
$mean
   56789
23.61538 29.4 59.11538 59.96154 31.44828

$sd
   56789
22.22445 18.20790 31.63584 39.68121 24.14182

$median
 5  6  7  8  9
18 23 60 52 23



-- 
   O__   Peter Dalgaard Ă˜ster Farimagsgade 5, Entr.B
  c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K
 (*) \(*) -- University of Copenhagen   Denmark  Ph:  (+45) 35327918
~~ - ([EMAIL PROTECTED])  FAX: (+45) 35327907

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] do.call without arguments?

2007-11-05 Thread Antje
Thank you very much! This is exactly what I need... I did not know that there 
is such a simple way :)

Antje


Peter Dalgaard schrieb:
> Antje wrote:
>> Hello,
>>
>> I have a vector containing strings of simple operation methods.
>>
>> methods <- c("mean","sd","median")e.g.
>>
>> Now, I'd like to apply these methods to my data and I thought, I could make 
>> a 
>> do.call. But these methods don't need any further arguments... Do I have to 
>> create an empty argument list?
>>
>> I wanted to use a tapply( data, factor, ??? do.call ??? )
>>
>> Can anybody help how to solve this problem?
>>
>>   
> Not sure what you mean by "any further arguments", but I wouldn't use
> do.call here:
> 
>> names(methods)<-methods
>> with(airquality,
> +  lapply(methods, function(f) tapply(Ozone,Month,FUN=f, na.rm=T)))
> $mean
>56789
> 23.61538 29.4 59.11538 59.96154 31.44828
> 
> $sd
>56789
> 22.22445 18.20790 31.63584 39.68121 24.14182
> 
> $median
>  5  6  7  8  9
> 18 23 60 52 23
> 
> 
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] do.call and plotting functions ...

2008-11-19 Thread Gabor Grothendieck
Try this:

f <- function(cmd, ...) {
cat("Hello\n")
mc <- match.call()
mc <- mc[-1]
eval.parent(mc)
cat("Goodbye\n")
}
f(plot, 1:10)


On Wed, Nov 19, 2008 at 8:57 AM, Roberto Brunelli
<[EMAIL PROTECTED]> wrote:
> I'm trying to write a simple wrapper for plotting functions to make
> them print to postscript, something like
>
> ploteps <- function(file, plotFunction, ...) {
>
>  args <- list(bquote(...))
>
>  # prepare postscript device
>
>  do.call(plot, args)
>
>  # close postscript device
> }
>
> I have inserted the bquote otherwise I get a lot of numbers in the
> plot when I plot/hist something. But if I invoke the function as
>
> ploteps("foo.eps", hist, xlab = "X")
>
> I get
>
> Error in bquote(...) : unused argument(s) (xlab = "X")
>
> What am I messing up?
>
>
> Thanks a lot,
>
> __
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


Re: [R] do.call and plotting functions ...

2008-11-19 Thread Prof Brian Ripley

The help pages (here for bquote) are your friend.

I don't think you really want to do this via do.call(), as you want some 
arguments evaluated and some unevaluated.  Rather, match.call(), alter it 
as you want, and then eval.parent it.  Something like


ploteps <- function(file, plotFunction, ...)
{
Call <- match.call()
fn <- deparse(substitute(plotFunction))
Call[[1]] <- as.name(fn)
Call$file <- Call$plotFunction <- NULL
postscript(file=file)
eval.parent(Call)
dev.off()
}
ploteps("foo.eps", hist, xlab = "X", rnorm(100))


On Wed, 19 Nov 2008, Roberto Brunelli wrote:


I'm trying to write a simple wrapper for plotting functions to make
them print to postscript, something like

ploteps <- function(file, plotFunction, ...) {

 args <- list(bquote(...))

# prepare postscript device

do.call(plot, args)

# close postscript device
}

I have inserted the bquote otherwise I get a lot of numbers in the
plot when I plot/hist something. But if I invoke the function as

ploteps("foo.eps", hist, xlab = "X")

I get

Error in bquote(...) : unused argument(s) (xlab = "X")

What am I messing up?


Thanks a lot,

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.



--
Brian D. Ripley,  [EMAIL PROTECTED]
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford, Tel:  +44 1865 272861 (self)
1 South Parks Road, +44 1865 272866 (PA)
Oxford OX1 3TG, UKFax:  +44 1865 272595

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.


[R] do.call() browser() hang with large data.frame

2008-02-13 Thread Alistair Gee
I have a problem similar to this:

http://tolstoy.newcastle.edu.au/R/help/06/02/21987.html

If I try to debug (via browser()) and the call stack has a do.call()
call with a large data frame, R hangs for a very long time. If,
instead, replaced the do.call() call with a direct call, there is no
hang.

What can I do?

I am using R 2.6.2.patched built from SVN today on Linux AMD64.

Here is my sample code:

#

options(deparse.max.lines=10)

### Create a big data frame with 1 million rows and 100 columns. This
do.call() is NOT the problem.
a <- do.call(data.frame,
 sapply(sprintf("col%d", 1:100), function(x) rnorm(1e6),
simplify=FALSE, USE.NAMES=TRUE))

### function I want to debug via browser()
foo <- function(aa, bb) {
  browser()  # I want to stop here to debug.
}

### This goes into the browser() immediately:
foo(aa=a,bb=2)

### This hangs for a very long time:
do.call(foo, list(aa=a, bb=2))

__
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.