I discovered a little problem when using the Windows NT release of R
1.0.1, and it's still there in R 1.1.0.
The boiled down version is this: I want to draw the following plot and
put it into a Postscript file:
x <- c(1,2,3,4); y1 <- c(1,2,3,4); y2 <- c(2,2,2,2)
Fred <- c(1,2)
postscript(file="d:/Bob/Papers/IFM/try2.ps")
plot(x,y1, type="l")
lines(x,y2,lty="33")
legend(1,4, c("y1","y2"), lty=Fred)
graphics.off()
This works fine. However, if I use Fred <- c(1,"33"), I get an
error
when trying to view hte file (using either Ghostscript or CorelDraw).
GhostScript gives me the message that I've included below.
Is this a bug, or am I missing something?
Bob
Oh yes, this is the GS message:
Loaded Ghostscript DLL C:\gstools\gs5.50\gsdll32.dll
Aladdin Ghostscript 5.50 (1998-9-11)
Copyright (C) 1998 Aladdin Enterprises, Menlo Park, CA. All rights
reserved.
This software comes with NO WARRANTY: see the file PUBLIC for details.
Displaying DSC file D:/Bob/Papers/IFM/try2.ps
Displaying page 1
Loading NimbusSanL-Regu font from
C:\gstools\gs5.50\fonts\n019003l.pfb... 1883690 574525 1329174 41921 1
done.
Loading NimbusSanL-Bold font from
C:\gstools\gs5.50\fonts\n019004l.pfb... 1923870 607231 1329174 44133 1
done.
Loading NimbusSanL-ReguItal font from
C:\gstools\gs5.50\fonts\n019023l.pfb... 1964050 641418 1329174 46118 1
done.
Loading NimbusSanL-BoldItal font from
C:\gstools\gs5.50\fonts\n019024l.pfb... 1984140 672771 1349264 51419 1
done.
Loading StandardSymL font from C:\gstools\gs5.50\fonts\s050000l.pfb...
2024320 710401 1349264 53445 1 done.
Unrecoverable error: rangecheck in setdash
Operand stack:
0 --nostringval--
--- Begin offending input ---
--- End offending input ---
file offset = 4285
gsdll_execute_cont returns -15
--
Bob O'Hara
Metapopulation Research Group
Division of Population Biology
Department of Ecology and Systematics
PO Box 17 (Arkadiankatu 7)
FIN-00014 University of Helsinki
Finland
tel: +358 9 191 7382 fax: +358 9 191 7301
email: bob.ohara at helsinki.fi
To induce catatonia, visit:
http://www.helsinki.fi/science/metapop/
I have yet to see any problem, however complicated, which, when you
looked at it in the right way, did not become still more complicated. -
Poul Anderson
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
"Anon." wrote:> > I discovered a little problem when using the Windows NT release of R > 1.0.1, and it's still there in R 1.1.0. > > The boiled down version is this: I want to draw the following plot and > put it into a Postscript file: > > x <- c(1,2,3,4); y1 <- c(1,2,3,4); y2 <- c(2,2,2,2) > Fred <- c(1,2) > > postscript(file="d:/Bob/Papers/IFM/try2.ps") > plot(x,y1, type="l") > lines(x,y2,lty="33") > legend(1,4, c("y1","y2"), lty=Fred) > graphics.off() > > This works fine. However, if I use Fred <- c(1,"33"), I get an error > when trying to view hte file (using either Ghostscript or CorelDraw). > GhostScript gives me the message that I've included below. > > Is this a bug, or am I missing something?In your first example "Fred" is numeric, in the second it is character: > c(1, "33") [1] "1" "33" As a simple workaround try: > c("solid", "33") The same problem occurs here: > postscript(file="test.ps") > plot(1:10) > lines(2:3, 5:6, lty="1") > dev.off() (WinNT4.0, R-1.1.0) Looks like the postscript device don't convert the character "1" to solid and also gives no warning message ... Regards, Uwe Ligges -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-help-request at stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Anon wrote:
...However, if I use Fred <- c(1,"33")...
Is this a bug, or am I missing something?
This is an interesting problem. It boils down to the fact that
PostScript expects an array (even if it's empty) and an offset for
"setdash". Normally, a solid line is specified with an empty array
and
zero offset. However, if R gets specs that convert to zero and puts a
zero in the array, the PostScript interpreter will barf. Zero can
appear, but there must be at least one non-zero number in the array.
Hexadecimal strings supplied to lty are converted to array elements, but
a single character "1" seems to produce "0.00". Remember
that the c()
operater will coerce the number 1 to the string "1" when combining it
with "33". That is, it's probably a bad idea to mix the two
methods of
specifying line types with "lty".
A possible fix is to insert a test for zero in the function
SetLineStyle() - devPS.c:
static void SetLineStyle(int newlty, double newlwd, DevDesc *dd)
{
PostScriptDesc *pd = (PostScriptDesc *) dd->deviceSpecific;
int i, ltyarray[8];
int sum = 0;
if (pd->lty != newlty || pd->lwd != newlwd) {
pd->lwd = newlwd;
pd->lty = newlty;
PostScriptSetLineWidth(pd->psfp, dd->gp.lwd*0.75);
for(i = 0; i < 8 && newlty & 15 ; i++) {
ltyarray[i] = newlty & 15;
sum += ltyarray[i];
newlty = newlty >> 4;
}
if(!sum) i = 0;
PostScriptSetLineTexture(pd->psfp, ltyarray, i, dd->gp.lwd *
0.75);
}
}
producing a solid line when all elements of 'ltyarray' are zero.
Jim
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !) To: r-help-request at
stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._