Manlio Calvi
2014-Jan-22 22:10 UTC
[R] xyplots in lattice - strange behaviour, possible bug?
Hello everyone, I'm very green on R, I'm following a Coursera course about it when I hit a problem when I rewrote the same code the professor use in the lecture. I'm running Win 7 x64, R 3.0.2 x64 and the last version of Rstudio IDE I put up this script: library(lattice) x <- rnorm (100) z <- x + rnorm(100) f <- gl(2,50,labels =c("Groups 1" , "Groups 2")) xyplot (z ~ x | f, panel = function (x, z, ...) { panel.xyplot(x,z, ...) panel.abline(h = median(z), lty=2 )}) In my box don't work, it give no error in the terminal, the plotting windonw will be opened, the graphbox drawed with all the ticks and the titles as intended but instead of the actual data plot inside the graph I have this error "Error using packet <x> argment "z" is missing, with no default" where <x> is 1 or 2 as the script draw two graphs. I reported this behaviour in the lecture forum and someone replicated it. I replicated this behaviour even with R alone running the above script with the same results. If I call traceback() no value is given, there is no traceback. Apparently not everyone could replicate this behaviour for some reason. As you could see the code must work but didn't. A similar thing happens if I change the part after the function with another like: ... <same code of above>... panel= function(x,y, ...) { panel.xyplot(x,z, ...) fit <- lm(y~x) panel.abline(fit) }) but don't happens if I call a xyplot without calling a function in it. Have any ideas?
Bert Gunter
2014-Jan-22 23:02 UTC
[R] xyplots in lattice - strange behaviour, possible bug?
Well, if the professor wrote that, it wouldn't have run for him either! You need to take better notes. What's going on: You need to distinguish between formal and actual arguments. ?panel.xyplot tells you that the formal arguments for this function are x,**y** ,... (emphasis added) and NOT x,**z**,... The **actual** argument for y passed to the function will be z. So change your "z" to a "y" in your function call and it will run: library(lattice) x <- rnorm (100) z <- x + rnorm(100) f <- gl(2,50,labels =c("Groups 1" , "Groups 2")) xyplot (z ~ x | f, panel = function (x, y, ...) { panel.xyplot(x,y, ...) panel.abline(h = median(y), lty=2 )}) Cheers, Bert Bert Gunter Genentech Nonclinical Biostatistics (650) 467-7374 "Data is not information. Information is not knowledge. And knowledge is certainly not wisdom." H. Gilbert Welch On Wed, Jan 22, 2014 at 2:10 PM, Manlio Calvi <manlio.calvi at gmail.com> wrote:> Hello everyone, > > I'm very green on R, I'm following a Coursera course about it when I > hit a problem when I rewrote the same code the professor use in the > lecture. > I'm running Win 7 x64, R 3.0.2 x64 and the last version of Rstudio IDE > > I put up this script: > > > library(lattice) > x <- rnorm (100) > z <- x + rnorm(100) > f <- gl(2,50,labels =c("Groups 1" , "Groups 2")) > xyplot (z ~ x | f, > panel = function (x, z, ...) { > panel.xyplot(x,z, ...) > panel.abline(h = median(z), > lty=2 > )}) > > > In my box don't work, it give no error in the terminal, the plotting > windonw will be opened, the graphbox drawed with all the ticks and the > titles as intended but instead of the actual data plot inside the > graph I have this error "Error using packet <x> argment "z" is > missing, with no default" where <x> is 1 or 2 as the script draw two > graphs. > > I reported this behaviour in the lecture forum and someone replicated it. > > I replicated this behaviour even with R alone running the above script > with the same results. > > If I call traceback() no value is given, there is no traceback. > > Apparently not everyone could replicate this behaviour for some reason. > > As you could see the code must work but didn't. > > A similar thing happens if I change the part after the function with > another like: > > ... <same code of above>... > panel= function(x,y, ...) { > panel.xyplot(x,z, ...) > fit <- lm(y~x) > panel.abline(fit) > }) > > but don't happens if I call a xyplot without calling a function in it. > > Have any ideas? > > ______________________________________________ > 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.