[Rd] xspline(..., draw=FALSE) fails if there is no open device (PR#10727)

Peter Dalgaard p.dalgaard at biostat.ku.dk
Fri Feb 8 15:42:52 CET 2008


jari.oksanen at oulu.fi wrote:
> Full_Name: Jari Oksanen
> Version:  2.6.2 RC (2008-02-07 r44369)
> OS: Linux
> Submission from: (NULL) (130.231.102.145)
>
>
> Even if function xspline() is called with argument draw=FALSE, it requires a
> graphics device (that it won't use since it was draw=FALSE). I run into this
> because I intended to use xspline within a function (that does not yet draw:
> there is plot method for that), and the function failed when called in a virgin
> environment. 
>
> Here is an example in a virgin environemt just after starting R:
>
>   
>> out <- xspline(c(0,1,0), c(1,0,1), draw=FALSE)
>>     
> Error in xspline(c(0, 1, 0), c(1, 0, 1), draw = FALSE) : 
>   plot.new has not been called yet
>   
>> str(out)
>>     
> Error in str(out) : object "out" not found
>
> This works:
>
>   
>> plot(0)
>> out <- xspline(c(0,1,0), c(1,0,1), draw=FALSE)
>> str(out)
>>     
> List of 2
>  $ x: num [1:3] 0 1 0
>  $ y: num [1:3] 1 0 1
>
> This won't:
>
>   
>> dev.off()
>>     
> null device 
>           1 
>   
>> xspline(c(0,1,0), c(1,0,1), draw=FALSE)
>>     
> Error in xspline(c(0, 1, 0), c(1, 0, 1), draw = FALSE) : 
>   plot.new has not been called yet
>
> R graphics internal are black magic to me. However, it seems that the error
> messge comes from function GCheckState(DevDesc *dd) in graphics.c, which is
> called by do_xspline(SEXP call, SEXP op, SEXP args, SEXP env) in plot.c even
> when xspline was called with draw = FALSE (and even before getting the argument
> draw into do_xspline). It seems that graphics device is needed somewhere even
> with draw = FALSE, since moving the  GCheckState() test after findig the value
> draw, and executing the test only if draw=TRUE gave NaN as the numeric output. 
>
> If this is documented behaviour, the documentation escaped my attention and beg
> for pardon. It may be useful to add a comment on the help page saying that an
> open graphics device is needed even when unused with draw=FALSE.
>
>   

I think the reason is that 2d splines are aspect ratio dependent.  
There's this loop inside,

    for (i = 0; i < nx; i++) {
        xx[i] = x[i];
        yy[i] = y[i];
        GConvert(&(xx[i]), &(yy[i]), USER, DEVICE, dd);
    }
 
and that will not work without knowing how to convert to device 
coordinates. The default for "border" may get you first, though.  That 
seems to be documented incorrectly, by the way.

    -p

> Cheers, Jari Oksanen
>
>  platform = i686-pc-linux-gnu
>  arch = i686
>  os = linux-gnu
>  system = i686, linux-gnu
>  status = RC
>  major = 2
>  minor = 6.2
>  year = 2008
>  month = 02
>  day = 07
>  svn rev = 44369
>  language = R
>  version.string = R version 2.6.2 RC (2008-02-07 r44369)
>
> Locale:
> LC_CTYPE=en_GB.UTF-8;LC_NUMERIC=C;LC_TIME=en_GB.UTF-8;LC_COLLATE=en_GB.UTF-8;LC_MONETARY=en_GB.UTF-8;LC_MESSAGES=en_GB.UTF-8;LC_PAPER=en_GB.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_GB.UTF-8;LC_IDENTIFICATION=C
>
> Search Path:
>  .GlobalEnv, package:stats, package:graphics, package:grDevices, package:utils,
> package:datasets, package:methods, Autoloads, package:base
>
> ______________________________________________
> R-devel at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-devel
>   


-- 
   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



More information about the R-devel mailing list