vincenzo.2.di-iorio at gsk.com
2008-Nov-11 17:15 UTC
[R] Retrieving x argument name from a trellis object in R 2.8.0
Dear all, let consider the following function: Fun1 <- function() { library(lattice) plot1 <- 1:10~1:10 pl1 <- xyplot(plot1) return(pl1$call$x) } In R 2.5.0 (or older version) we have> Fun1()plot1 but starting from R 2.5.1 until the latest R 2.8.0 we obtain instead> Fun1()NULL because pl1$call seems to be equal to xyplot() without arguments. Something like xyplot(x=plot1) doesn?t work either. Again we have that pl1$call is equal to xyplot() without arguments The situation is slightly different if we call the xyplot in the global environment:> plot1 <- 1:10~1:10 > pl1 <- xyplot(plot1) > pl2 <- xyplot(x=plot1)then we have> pl1$callxyplot(plot1)> pl1$call$xNULL but at least> pl2$callxyplot(x = plot1)> pl2$call$xplot1 Someone knows if in R 2.8.0 it is possible to retrieve the name of the x argument (i.e. plot1) directly from an object of class ?trellis? when the corresponding lattice function (e.g. xyplot) is inside another function (e.g. Fun1)? Thanks in advance Vincenzo ----------------------------------------------------------------------------------- Vincenzo Luca Di Iorio Consultant PME User support - GSK R&D Limited ----------------------------------------------------------------------------------- [[alternative HTML version deleted]]
Deepayan Sarkar
2008-Nov-12 06:04 UTC
[R] Retrieving x argument name from a trellis object in R 2.8.0
On 11/11/08, vincenzo.2.di-iorio at gsk.com <vincenzo.2.di-iorio at gsk.com> wrote:> Dear all, > > let consider the following function: > > Fun1 <- function() { > library(lattice) > plot1 <- 1:10~1:10 > pl1 <- xyplot(plot1) > return(pl1$call$x) > } > > In R 2.5.0 (or older version) we have > > > Fun1() > plot1 > > but starting from R 2.5.1 until the latest R 2.8.0 we obtain instead > > > Fun1() > NULL > > because pl1$call seems to be equal to xyplot() without arguments. > > Something like xyplot(x=plot1) doesn?t work either. Again we have that > pl1$call is equal to xyplot() without arguments > > The situation is slightly different if we call the xyplot in the global > environment: > > > plot1 <- 1:10~1:10 > > pl1 <- xyplot(plot1) > > pl2 <- xyplot(x=plot1) > > then we have > > > pl1$call > xyplot(plot1) > > pl1$call$x > NULL > > but at least > > > pl2$call > xyplot(x = plot1) > > pl2$call$x > plot1This is what I would have expected. I'm surprised at the odd behaviour when xyplot() is called inside a function, which is probably caused by my lack of understanding of how sys.call() works. However, the 'call' component is provided mainly for cosmetic reasons, and was never intended to be used programmatically. Why do you need this? -Deepayan> Someone knows if in R 2.8.0 it is possible to retrieve the name of the x > argument (i.e. plot1) directly from an object of class ?trellis? when the > corresponding lattice function (e.g. xyplot) is inside another function > (e.g. Fun1)? > > Thanks in advance > Vincenzo > > ----------------------------------------------------------------------------------- > Vincenzo Luca Di Iorio > Consultant PME User support - GSK R&D Limited > ----------------------------------------------------------------------------------- > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at 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. >