Marie Sivertsen
2009-Feb-05 13:34 UTC
[R] Problem with plotting data from within a function
Dear List, I try to develop code where plotting functions are embeded in my own functions. The following is simplified example:> test <- function() { > data <- data.frame(x=rep(1:2, each=50), y=rnorm(100)) > library(lattice) > attach(data) > xyplot(y~x) > detach() >} >test()As far as I understand R, when test is called this should create one local data frame, attach it that it's columns are available directly, load the lattice library, plot data, and then detach the data frame. But, when I call test, nothing happens. I see not plot and no error message. When I try the script from Rscript, nothing happens too. But when I copy the inside code from test and run it directly, all seems to work. What am I doing wrong? Is this a question to be asked here, or to the developers of lattice package? Mvh. Marie [[alternative HTML version deleted]]
Peter Dalgaard
2009-Feb-05 13:57 UTC
[R] Problem with plotting data from within a function
Marie Sivertsen wrote:> Dear List, > > I try to develop code where plotting functions are embeded in my own > functions. The following is simplified example: > >> test <- function() { >> data <- data.frame(x=rep(1:2, each=50), y=rnorm(100)) >> library(lattice) >> attach(data) >> xyplot(y~x) >> detach() >> } >> test() > > > As far as I understand R, when test is called this should create one local > data frame, attach it that it's columns are available directly, load the > lattice library, plot data, and then detach the data frame. But, when I > call test, nothing happens. I see not plot and no error message. When I > try the script from Rscript, nothing happens too. But when I copy the > inside code from test and run it directly, all seems to work. What am I > doing wrong? Is this a question to be asked here, or to the developers of > lattice package?You need to print() your plot: http://cran.r-project.org/doc/FAQ/R-FAQ.html#Why-do-lattice_002ftrellis-graphics-not-work_003f It is probably OK to ask elementary questions on widely used packages here. Actual bug reports should go to the maintainers and for "specialist" questions, you might consider the relevant R-SIG-* group (of which in this case there appears to be none, but there would be one for, say, genetic marker analysis). -- O__ ---- Peter Dalgaard ?ster Farimagsgade 5, Entr.B c/ /'_ --- Dept. of Biostatistics PO Box 2099, 1014 Cph. K (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907