[R] Re: printing reals from C with digits -- once more

ripley@stats.ox.ac.uk ripley at stats.ox.ac.uk
Sun Feb 2 16:19:02 CET 2003


On Sun, 2 Feb 2003, Ott Toomet wrote:

> Thank for Brian D. Ripley for the answer to my previous question.  
> 
> My aim is to print single values from different real vectors with
> different digits option.  This is quite a possible with Rprintf() but
> that one supprots printing format as C does, not in R native way
> (setting digits=7 or printing with "%12.7f" are two quite different
> things).  So I would like to find something more R-ish.

R *does* use C printing formats, and all you need to so is to track those
down in the sources.

> PrintValue() seems promising (it understands when I change
> options(digits) but I did not get it to print a single value.  I tried
> 
>   SEXP variable;
>   PrintValue(VECTOR_ELT(variable, i));
> 
> which lead to crash, while
> 
>   PrintValue(variable);
> 
> prints the whole vector.  

You need to create a vector of length 1 to print one value.

> StringFromReal() (and printing as CHAR) is otherwise nice but I dont
> know how can I make it to understand options(digits).

It's not a public entry point, and support for options(digits) is in the 
callers.

> Can anybody suggest me a way for this?
> 
> Best wishes,
> 
> Ott
> 
> 
> BTW, can I be sure that everything defined in /usr/lib/R/include and
> R_ext are (more or less) safe to use?

No, read R_exts for what is in the API and what is not.

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