Puzzled by the "call" component of object returned by xyplot() from lattice.

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Puzzled by the "call" component of object returned by xyplot() from lattice.

Rolf Turner

I have written a function that calls xyplot() from the lattice package.
In this function (which is actually a method for plot(), I assign a value

    plotObj <- xyplot(fmla,groups=.......)

and then either either do print(plotObj) --- to display a plot as well
as returning plotObj, to be kept for future use/reference.

I have just noticed that if I do

     p1 <- plot(X)
and

    p2 <- plot(X,transform=FALSE)

where X is of course an object of the class for which my method gets
used, I get p1$call to be

    xyplot(X)

and p2$call to be

     xyplot(X, transform = TRUE)

That is, it gives the arguments supplied to the calling function (my
plot method) in the call component, and not the arguments to xyplot().

This seems strange to me.  Should I have, uh, expected this?  *Why*
should I have expected this?  Can anyone explain?

I guess it's just idle curiosity; nothing really riding on it.

Thanks.

cheers,

Rolf

--
Honorary Research Fellow
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.
Reply | Threaded
Open this post in threaded view
|

Re: Puzzled by the "call" component of object returned by xyplot() from lattice.

Bert Gunter-2
Rolf:

This behavior has nothing to do with S3 methods:

> f <- function(x,y,...) xyplot(y~x, col = "red",...)
> x <- 1:5; y <- runif(5)
> z <- f(x,y)
> z$call
xyplot(x, y)

I have **not** studied the lattice code, but assuming that it is using
match.call() to get the call it returns, it looks like the sys.call
argument it (i.e. match.call()) is given is looking up higher in the
call stack than sys.parent().

Hopefully Deepayan or a suitable someone else can provide a definitive answer.

Cheers,
Bert

On Fri, Mar 27, 2020 at 11:16 PM Rolf Turner <[hidden email]> wrote:

>
>
> I have written a function that calls xyplot() from the lattice package.
> In this function (which is actually a method for plot(), I assign a value
>
>     plotObj <- xyplot(fmla,groups=.......)
>
> and then either either do print(plotObj) --- to display a plot as well
> as returning plotObj, to be kept for future use/reference.
>
> I have just noticed that if I do
>
>      p1 <- plot(X)
> and
>
>     p2 <- plot(X,transform=FALSE)
>
> where X is of course an object of the class for which my method gets
> used, I get p1$call to be
>
>     xyplot(X)
>
> and p2$call to be
>
>      xyplot(X, transform = TRUE)
>
> That is, it gives the arguments supplied to the calling function (my
> plot method) in the call component, and not the arguments to xyplot().
>
> This seems strange to me.  Should I have, uh, expected this?  *Why*
> should I have expected this?  Can anyone explain?
>
> I guess it's just idle curiosity; nothing really riding on it.
>
> Thanks.
>
> cheers,
>
> Rolf
>
> --
> Honorary Research Fellow
> Department of Statistics
> University of Auckland
> Phone: +64-9-373-7599 ext. 88276
>
> ______________________________________________
> [hidden email] mailing list -- To UNSUBSCRIBE and more, see
> 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.

______________________________________________
[hidden email] mailing list -- To UNSUBSCRIBE and more, see
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.