From hb at stat.berkeley.edu  Wed Feb 27 11:50:02 2008
From: hb at stat.berkeley.edu (Henrik Bengtsson)
Date: Wed, 27 Feb 2008 02:50:02 -0800
Subject: [Rd] Warnings generated by log2()/log10() are really
	large/takes a long time to display
In-Reply-To: <alpine.LFD.1.00.0802270850350.17186@gannet.stats.ox.ac.uk>
References: <59d7961d0802262203y16b6b24dmebca4a29deca59f5@mail.gmail.com>
	<18373.8956.152890.662124@stat.math.ethz.ch>
	<alpine.LFD.1.00.0802270850350.17186@gannet.stats.ox.ac.uk>
Message-ID: <59d7961d0802270250u7edbf378s9ccc9282cdc22fdb@mail.gmail.com>

On Wed, Feb 27, 2008 at 12:56 AM, Prof Brian Ripley
<ripley at stats.ox.ac.uk> wrote:
> On Wed, 27 Feb 2008, Martin Maechler wrote:
>
>  > Thank you Henrik,
>  >
>  >>>>>> "HenrikB" == Henrik Bengtsson <hb at stat.berkeley.edu>
>  >>>>>>     on Tue, 26 Feb 2008 22:03:24 -0800 writes:
>  >
>  > {with many superfluous empty statements ( i.e., trailing ";" ):
>
>  Indeed!

I like to add a personal touch to the code I'm writing ;)

Seriously, I added them here as a bait in order to get a chance to say
that I finally found a good reason for adding the semicolons.  If you
cut'n'paste code from certain web pages it may happen that
newlines/carriage returns are not transferred and all code is pasted
into the same line at the R prompt.  With semicolons you still get a
valid syntax.  I cannot remember under what conditions this happened -
if it was for certain web browser, web page/blog, online page editor,
OS and so, but I'm quite sure it was while I've put online code
examples for my latest project.  Maybe someoneelse also has noticed
this?

>
>
>
>  >    HenrikB> x <- rnorm(1e6);
>  >
>  >    [................]
>  >
>  >
>  >    HenrikB> y <- log2(x);  # or log10(x)
>  >    HenrikB> w <- warnings();
>  >    HenrikB> print(object.size(w));
>  >    HenrikB> ## [1] 8000536
>  >    HenrikB> str(w);
>  >    HenrikB> ## List of 1
>  >    HenrikB> ##  $ NaNs produced: language log(c(2.12082478659910,
>  >    HenrikB> 1.40263187453398, 1.574125429
>  >    HenrikB> ## 83486, -0.816399069824751,  0.215940065840533, 1.20975177084379,
>  >    HenrikB> -0.340287874362
>  >    HenrikB> ## 813, 0.117151537611550,  ...
>  >    HenrikB> ##  - attr(*, "dots")= list()
>  >    HenrikB> ##  - attr(*, "class")= chr "warnings"
>  >
>  >    HenrikB> Note also how long it takes to display and str() the warning.
>  >
>  > Yes, indeed.
>  > It's a subtle problem and happens
>  > because in do_log1arg() a new call is constructed in which 'x'
>  > has already been evaluated.
>  >
>  > A subtle fix to the subtle problem
>  > is to replace  CAR(args) by CADR(call) in there
>  >
>  > --- arithmetic.c      (Revision 44626)
>  > +++ arithmetic.c      (working copy)
>  > @@ -1372,7 +1372,9 @@
>  >     if(PRIMVAL(op) == 10) tmp = ScalarReal(10.0);
>  >     if(PRIMVAL(op) == 2)  tmp = ScalarReal(2.0);
>  >
>  > -    PROTECT(Call = lang3(install("log"), CAR(args), tmp));
>  > +    /* CADR(call) instead of CAR(args), since 'args' have been
>  > +     * evaluated in Dispatch*(..) above : */
>  > +    PROTECT(Call = lang3(install("log"), CADR(call), tmp));
>  >     res = eval(Call, env);
>  >     UNPROTECT(1);
>  >     return res;
>  >
>  > -----
>  >
>  > That does fix the problem you've reported (and passes "make check")
>  > but I'm not quite at ease with it, since it will lead to
>  > effectively evaluate the argument *twice*.
>  >
>  > A different approach that I'd find cleaner
>  > would be to *not* construct and eval() a
>  > new Call inside do_log1arg, but I assume there had been a good
>  > reason for doing things they way they are now...
>
>  There was (although possibly no longer -- there was a bug in S4 dispatch
>  of primitives that failed to re-promise args).
>
>  The real issue is somewhere else entirely, the complete deparse in
>  print.warnings.

Thank you both for looking into this.

Henrik

>
>  >
>  > Martin Maechler, ETH Zurich
>  >
>  > ______________________________________________
>  > R-devel at r-project.org mailing list
>  > https://stat.ethz.ch/mailman/listinfo/r-devel
>  >
>
>  --
>  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
>



[Rd] Warnings generated by log2()/log10() are really large/takes a long time to display
Henrik Bengtsson