Heinz Tuechler <[EMAIL PROTECTED]> writes:
> > mytable1<-function(x,y){table(x,y)}
> > mytable1(charly, delta)
> y
> x 1 2
> 1 2 1
> 2 3 4
> If I define the function in the following way, it does what I wish, namely
> it returns output equivalent to the simple call "table(charly, delta)".
> > mytable2<-function(x,y){
> + cat("table(",as.symbol((deparse(substitute(x)))),
> + "," , as.symbol(deparse(substitute(y))),")\n",
> + file="temp",sep="",append=F)
> + eval(parse("temp",n=-1))
> + }
> > mytable2(charly, delta)
> delta
> charly 1 2
> 1 2 1
> 2 3 4
> >
> I assume that there is a better way to solve this problem and I would be
> happy about hints, where to find solutions in the documentation.
What did Thomas L. say recently? "If the answer involves parse(), you
probably asked the wrong question", I think it was.
The canonical way is
mytable <- function(x,y) eval.parent(substitute(table(x,y)))
or, you could of course modify the names(dimnames(...)) and just pass
the names along.
--
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - ([EMAIL PROTECTED]) FAX: (+45) 35327907
______________________________________________
[email protected] mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html