Ritter, Christian C GSMCIL-GSTMS/2
2005-Jul-12 11:08 UTC
[R] unexpected behavior in bwplot
R-2.1.1 on windows XP I just noticed something unpleasant when using bwplot (from lattice). In order to satisfy a wish from a client, I needed to produce sets of boxplots conditioned by another factor. My client didn't like the look of the boxplots (by default, they have a star to mark the median, instead of the commonly used line). I told him "no problem" dumped panel.bwplot, added a line at the median, commented out the star, and sourced it back in as panel.mybwplot. Then I tried to call it with bwplot(...,panel="panel.mybwplot"), but this hit two roadblocks. The first one was relatively easy: it didn't find the function current.viewport (from grid). Explicitely loading the package grid was sufficient (current.viewport is exported there). But then it stopped on chooseFace. It was not obvious to find where chooseFace was (in lattice, but not as an exported function in the namespace) and how to make it callable. I finally clobbered it by defining chooseFace<-lattice:::chooseFace. This certainly worked but is very inelegant. Could anyone point me to cleaner ways to do this? On the other hand, I would have preferred if panel.bwplot would not use functions not exported to the outer namespace (or if lattice would make sure that all functions called in the standard panel functions were exported to the outer namespace). It is very common that we have to slightly modify standard panel functions and it is quite annoying having to chase for evenually hidden functions called by them. Comments? Thanks in advance, Christian Ritter Functional Specialist Statistics Shell Coordination Centre S.A. Monnet Centre International Laboratory, Avenue Jean Monnet 1, B-1348 Louvain-La-Neuve, Belgium Tel: +32 10 477 349 Fax: +32 10 477 219 Email: christian.ritter@shell.com Internet: http://www.shell.com/chemicals [[alternative HTML version deleted]]
I had a similar problem when trying to modify a function from lattice. I second the opinion that it would be nice if lattice exported more things. My soulution was to give my function the same environment as the one I had copied, i.e. try: environment(panel.mybwplot) <- environment(panel.bwplot) I have included a line like this at the end of the script file that defines my new/modified lattice functions, and as long as lattice is loaded first (could wrap the above in the body of an if statement that calls library or require) then everything works fine (having the same environment lets the new function find the non-exported functions). Hope this helps, Greg Snow, Ph.D. Statistical Data Center, LDS Hospital Intermountain Health Care greg.snow at ihc.com (801) 408-8111>>> "Ritter, Christian C GSMCIL-GSTMS/2" <christian.ritter at shell.com>07/12/05 05:08AM >>> R-2.1.1 on windows XP I just noticed something unpleasant when using bwplot (from lattice). In order to satisfy a wish from a client, I needed to produce sets of boxplots conditioned by another factor. My client didn't like the look of the boxplots (by default, they have a star to mark the median, instead of the commonly used line). I told him "no problem" dumped panel.bwplot, added a line at the median, commented out the star, and sourced it back in as panel.mybwplot. Then I tried to call it with bwplot(...,panel="panel.mybwplot"), but this hit two roadblocks. The first one was relatively easy: it didn't find the function current.viewport (from grid). Explicitely loading the package grid was sufficient (current.viewport is exported there). But then it stopped on chooseFace. It was not obvious to find where chooseFace was (in lattice, but not as an exported function in the namespace) and how to make it callable. I finally clobbered it by defining chooseFace<-lattice:::chooseFace. This certainly worked but is very inelegant. Could anyone point me to cleaner ways to do this? On the other hand, I would have preferred if panel.bwplot would not use functions not exported to the outer namespace (or if lattice would make sure that all functions called in the standard panel functions were exported to the outer namespace). It is very common that we have to slightly modify standard panel functions and it is quite annoying having to chase for evenually hidden functions called by them. Comments? Thanks in advance, Christian Ritter Functional Specialist Statistics Shell Coordination Centre S.A. Monnet Centre International Laboratory, Avenue Jean Monnet 1, B-1348 Louvain-La-Neuve, Belgium Tel: +32 10 477 349 Fax: +32 10 477 219 Email: christian.ritter at shell.com Internet: http://www.shell.com/chemicals [[alternative HTML version deleted]] ______________________________________________ R-help at stat.math.ethz.ch mailing list https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html
On 7/12/05, Ritter, Christian C GSMCIL-GSTMS/2 <christian.ritter at shell.com> wrote:> R-2.1.1 on windows XP > > I just noticed something unpleasant when using bwplot (from lattice). > > In order to satisfy a wish from a client, I needed to produce sets of boxplots conditioned by another factor. My client didn't like the look of the boxplots (by default, they have a star to mark the median, instead of the commonly used line). I told him "no problem" dumped panel.bwplot, added a line at the median, commented out the star, and sourced it back in as panel.mybwplot. > > Then I tried to call it with bwplot(...,panel="panel.mybwplot"), but this hit two roadblocks. The first one was relatively easy: it didn't find the function current.viewport (from grid). Explicitely loading the package grid was sufficient (current.viewport is exported there). But then it stopped on chooseFace. It was not obvious to find where chooseFace was (in lattice, but not as an exported function in the namespace) and how to make it callable. I finally clobbered it by defining chooseFace<-lattice:::chooseFace. This certainly worked but is very inelegant. Could anyone point me to cleaner ways to do this? > > On the other hand, I would have preferred if panel.bwplot would not use functions not exported to the outer namespace (or if lattice would make sure that all functions called in the standard panel functions were exported to the outer namespace). It is very common that we have to slightly modify standard panel functions and it is quite annoying having to chase for evenually hidden functions called by them. Comments? >I agree that this is a problem, but I don't know what a good solution is. I can certainly export more functions (writing documentation is the only hard work). However, chooseFace is a hack which definitely isn't worth exporting. I think the best solution in this case is for me to rewrite panel.bwplot using lattice wrappers line panel.points and panel.lines (and panel.rect, which doesn't exist yet). That may take a little time. Please let me know of other similar situations if you encounter them. Deepayan