[R] Lattice levelplots and (partial) failure on some devices ----Long

Prof Brian Ripley ripley at stats.ox.ac.uk
Fri Jun 13 11:23:40 CEST 2003


This is a Windows run-time quirk (bug): Linux gives nan.  It's a problem
with what grid/lattice sends the driver.  Rather than put protection code 
in each driver, it needs to be in the central graphics code.

We've been here several times before ....

On Thu, 12 Jun 2003, Joel Kincaid wrote:

> 
> 
> Dear Community,
> 
> (win XP home, sp1; R1.7 -- patched version, binary download, version of 
> lattice obtained with patched version; the following applies to 1.6.2 as 
> well.)
> 
> The following message was originally composed to seek help. However I 
> have 'hacked' a solution to the following behavior, but none the less 
> someone might find this interesting.
> 
> To reproduce my 'problem' you can use the following code:
> 
> library(lattice)
> hypodata <- expand.grid(ProdMult = seq(0,1,by=.1),
>                          WfMult = seq(0,1,by=.1),
>                          Tr=c(0,75))
> hypodata$UnCC <- 4.6 + (hypodata$ProdM^2) * (hypodata$Wf^3 )
> hypodata$UnCC[1:121]   <- 4.6
> testfault <-    levelplot(UnCC ~ WfMult + ProdMult | Tr,
>                  col.regions=grey(16:0/16),
>                  data=hypodata)
> 
> If one enters
>  > testfault
> 
> the you get the expected result (if a bit uninteresting). This being a 
> blank first panel (hmmm, shouldn't it be 4.6) and then a second panel 
> with a filled contour. (I have a much larger set of simulated data --- 
> about 450 pages of figures, this 'blank' panel appears periodically and 
> is of interest...)
> 
> If you do
> < pdf(file="testfault.pdf") #Error
> < testfault
> < dev.off()
> or postscript(...)
> 
> then the file is created. Try to open with pdf reader or ghost 
> script---can't be done!, you get the following error from the pdf file:
> 
> "There was an error processing a page. Two Few operands."
> 
> and then you get....
> 
> "An unrecognized token '-1.#J' was found."
> 
> and then a blank sheet. Ghostscript returns the first occurrence of the 
> token and then dies a proper death.
> 
> Upon opening the pdf file in a text editor one easily locates the 
> following chunk of 'stuff'
> ......
> pdf stuff>>ET
> pdf stuff>>Q q -216.00 -216.00 864.00 864.00 re W n
> pdf stuff>>Q q 49.70 37.14 153.47 358.88 re W n
> pdf stuff>>1.000 1.000 1.000 rg
> pdf stuff>>  -1.#J -1.#J m
> pdf stuff>>  -1.#J -1.#J l
> pdf stuff>>  -1.#J -1.#J l
> pdf stuff>>  -1.#J -1.#J l
> pdf stuff>>h f
> 
> A naive search and replace of -1.#J with 0.0 , and a save, does the 
> trick. The file will now open in a pdf reader (as well as ghostscript). 
> There is however, a message stating something to the effect that a 
> problem has been found, but the file is being 'rebuilt'.
> 
> Now what is interesting is that the above is only a problem for the pdf 
> and postscript devices --- other devices, e.g. win.metafile, png, jpg, 
> etc. work fine .
> 
> (However a similar setup, I'll track it down it someone thinks it would 
> be of use, will trigger a crash that seems to associated with the 
> 'ntdll.dll' dyn. lnk. library(?)
> E.g from the event viewer I get...
> 
> Faulting application rgui.exe, version 1.70.30515.0, faulting module 
> ntdll.dll, version 5.1.2600.1106, fault address 0x000267cd
> 
> 0000: 6c707041 74616369 206e6f69 6c696146
> 0010: 20657275 75677220 78652e69 2e312065
> 0020: 332e3037 35313530 6920302e 746e206e
> 0030: 2e6c6c64 206c6c64 2e312e35 30303632
> 0040: 3031312e 74612036 66666f20 20746573
> 0050: 32303030 64633736 0a0d
> )
> 
> 
> If you use the data above and try things with the base package plots --- 
> contour and filled.contour (for the constant 4.6 data),
> 
> contour gives the error message:
> ...stack imbalance in internal contour....
> and plots an empty graphics box. However it saves to all of the devices 
> exactly as on the screen device.
> 
> The following
>  >filled.contour( x=seq(0,1,by=.1),
>  >                y=seq(0,1,by=.1),
>  >                z=matrix(rep(4.6,121),nrow=11,ncol=11))
> gives  the expected 'slightly pink' filled contour and can be written to 
>   all of the devices with no problem.
> 
> Thus it appear to me that there is some interaction between some of the 
> devices and lattice (is the string "-1.#J" some kind of character set 
> for NA or NaN or NULL???). I tried to find the area in the lattice code 
> that seemed to deal with this issue  and found some call to (i guess) C 
> code around lines 4554 which deal with 'NA's in the data....however I 
> was a bit lost....(Also searching the base code I could find no 
> reference to the error message returned from the contour(....) example 
> above....)
> 
> 
> In summary, is there a way to avoid this issue and keep the 'blank' 
> panels, and not have to do this search and replace (on a 450 page pdf 
> file it takes about 15 mins ....),
> 
> cheers,
> Joel
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> 

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list