R-alpha: deparse bug

Martyn Plummer plummer@iarc.fr
Mon, 08 Sep 1997 10:52:40 +0200 (MET DST)

The deparse function has an argument "width.cutoff" which allows you
to set the width at which line breaking is attempted.  However, setting
this argument _permanently_ changes the line break width.

Looking at the source code ($RHOME/src/main/deparse.c), I see that the
width.cutoff argument sets the static variable "cutoff".  Although the
function do_deparse behaves correctly - overwriting cutoff with the
default value if not given a second argument -  other R functions (such
as print and edit) call deparse1 which doesn't do this. Hence they use
the modified cutoff value.

A quick fix would be to get do_deparse to reset cutoff to the default
value after calling deparse1 but before returning.


> #Use function trunc as an example
> #This normally prints on two lines
> trunc
function (x) 
ifelse(x < 0, ceiling(x), floor(x))
> #Now deparse with narrow cutoff
> deparse(trunc,20)
[1] "function (x) "             
[2] "ifelse(x < 0, ceiling(x), "
[3] "        floor(x))"         
> #Cutoff 20 is used next time you print anything
> trunc
function (x) 
ifelse(x < 0, ceiling(x), 
> #Cutoff is reset to default when you call
> #deparse without width.cutoff argument
> deparse(trunc)
[1] "function (x) "                      
[2] "ifelse(x < 0, ceiling(x), floor(x))"
> #Default cutoff (60) is now used when you print
> trunc
function (x) 
ifelse(x < 0, ceiling(x), floor(x))
r-devel 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-devel-request@stat.math.ethz.ch