From savicky at cs.cas.cz  Fri May 29 17:48:50 2009
From: savicky at cs.cas.cz (Petr Savicky)
Date: Fri, 29 May 2009 17:48:50 +0200
Subject: [Rd] as.numeric(levels(factor(x))) may be a decreasing sequence
In-Reply-To: <18975.59582.885300.549159@lynne.math.ethz.ch>
References: <20090523074454.GA17112@cs.cas.cz>
	<18973.42970.826686.173830@cmath-5.math.ethz.ch>
	<4A1DC057.80401@idi.ntnu.no>
	<18975.59582.885300.549159@lynne.math.ethz.ch>
Message-ID: <20090529154850.GC5939@cs.cas.cz>

On Fri, May 29, 2009 at 03:53:02PM +0200, Martin Maechler wrote:
> my version of *using* the function was
> 
> 1 SEXP attribute_hidden StringFromReal(double x, int *warn)
> 2 {
> 3   int w, d, e;
> 4   formatReal(&x, 1, &w, &d, &e, 0);
> 5   if (ISNA(x)) return NA_STRING;
> 6   else return mkChar(dropTrailing0(EncodeReal(x, w, d, e, OutDec), OutDec));
> 7 }
> 
> where you need to consider that mkChar() expects a 'const char*' 
> and EncodeReal(.) returns one, and I am pretty sure this was the
> main reason why Petr had used the two 'const char*' in (the
> now-named) dropTrailing0() definition. 

Yes, the goal was to accept the output of EncodeReal() with exactly the
same type, which EncodeReal() produces. A question is, whether the
output type of EncodeReal() could be changed to (char *). Then, changing
the output string could be done without casting const to non-const.

This solution may be in conflict with the structure of the rest of R code,
so i cannot evaluate, whether this is possible.

Petr.



[Rd] as.numeric(levels(factor(x))) may be a decreasing sequence
Petr Savicky