This project is read-only.

Problem generating PNG graphics, sometimes

Mar 20, 2013 at 9:50 PM

I am getting a strange problem that I am having trouble solving.
My R.NET application is getting the following error plotting to a PNG file.
Error in plot.xy(xy.coords(x, y), type = type, ...) : 
  invalid string in Cairo_StrWidth
Analysis Failed

R Stack Trace:
16: plot.xy(xy.coords(x, y), type = type, ...)
15: points.default(x, y, ...)
14: points(x, y, ...)
13: points2(x1, y1, pch = pch[ok], col = col[ok], cex = pt.cex[ok], 
        bg =[ok], lwd = pt.lwd[ok])
12: legend(usr[2] + xadj, usr[4], legend = legendTxt, text.col = col, 
        cex = 0.75, pch = pchTxt, lty = lty, col = col, bty = "n", 
        title = label(tData), title.col = 1, xpd = TRUE)
11: plot.scatterPlot2(data)
10: plot(data)
(The plot.scatterPlot2 function is one of mine)

If I run the exact same script directly in R there is no error.
To help isolate the issue I created the folowing script
png(width=11, height=8.5, units='in', res=144, pointsize=12, type='cairo' );
plot(1:10, pch=c(162,163,164,165,167,169,174));
usr <- par('usr');
legend(usr[2], usr[4], legend=as.character(1:10), cex=0.75, pch=c(162,163,164,165,167,169,174), bty='n', xpd=TRUE);
Running this script directly in R generates a 9.2K PNG file with a siimple plot.
Running this script through R.NET there are no errors generates a 0 byte PNG file. I have to execute a second "" instruction to get the PNG file to be closed.
After that the 2k PNG file is a blank page.

I have found 2 ways to fix this problems, but my users do not like either solution.
  1. Do not use type='cairo' in the call to png()
  2. Do not use 'pch' values greater than 128; like pch=c(12:18)
The cairo graphics produces better quality images that my users want.
I could stop using the larger 'pch' values, but my users like the extra ploting characters to choose from.

Does anybody have any ideas why this is happening or how it can be fixed?