[R] Retrieving x argument name from a trellis object in R 2.8.0

Deepayan Sarkar deepayan.sarkar at gmail.com
Thu Nov 13 02:23:25 CET 2008


On Wed, Nov 12, 2008 at 7:41 AM,  <vincenzo.2.di-iorio at gsk.com> wrote:
>
> Dear Deepayan,
>
> thanks for you quick response.
>
> The main idea is to use trellis_object$call$x as a label in a tcltk
> interface to choose one among several plots and perform a given task  (e.g.
> print on screen, export as pdf etc.). I've a script that works just fine in
> R 2.4.1 for instance, but not anymore in R >= 2.5.1 and I was wondering if
> there is a possibility to reproduce the old behaviour with the new R
> version.
>
> I can imagine few workarounds, but they lack flexibility (e.g. using always
> the same  vector of labels vec <- paste("Plot",1:n,sep='_')) or simplicity
> (e.g. providing the labels like argument to the function that create the
> tcltk interface).

You haven't given details of your use-case, but if it involves calling
xyplot etc. from your own function, then a fairly reliable option is
to replace the call component of the object inside that function; e.g.

Fun1 <- function() {
    library(lattice)
    plot1 <- 1:10 ~ 1:10
    call <- quote(xyplot(x = plot1))
    pl1 <- eval(call)
    pl1$call <- call
    print(pl1)
    return(pl1$call$x)
}

Otherwise, I don't think you can depend on getting the old behaviour.
I will try to track down the reason for the odd results that we
currently get if I have time, but it's not going to be a priority.

-Deepayan



More information about the R-help mailing list