[R] printing reals from C with digits
Prof Brian D Ripley
ripley at stats.ox.ac.uk
Wed Jan 29 10:02:05 CET 2003
On Wed, 29 Jan 2003, Ott Toomet wrote:
> I want to print real numbers in C code with different values for
> digits. How to do that?
Use Rprintf or PrintValue. You'll need to work hard to convince me that
Rprintf is not adequate.
> As I have understood, what I should do is to call
>
> StringFromReal()
That's a coercion, not a printing routine.
> which calls FormatReal(), that one suggests the parameters (width,
> decimal places and exponential form). FormatReal() includes
>
> eps = pow(10.0, -(double)R_print.digits);
>
> So I guess I have to change the value of R_print.digits.
> R_print.digits is defined in include/Print.h in the package source,
> but unfortunately the installed version (in /usr/lib/R/include/R_ext) is
> quite a different.
R_ext/Print.h and Print.h are not the same thing: one is not a version of
the other. The routines you mention are not documented in R-exts, and are
not part of the API.
> I guess that is because the structure is not meant
> to be accessible by user, although some system routines alter
> R_print.digits directly.
(Only the coercion and print routines!)
> So are there any good way to achieve it?
Temporarily change the options(digits) and call PrintValue(). You are not
meant to (and it is not safe to) mess with R's printing internals, and
these structures change even at patch releases.
--
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
More information about the R-help
mailing list