[R] a rounding option for \Sexpr{}?

Yihui Xie xie at yihui.name
Fri Nov 19 16:12:22 CET 2010


Maybe this should go to R-devel as a wishlist:

Can we change as.character() to format() in this line in
src/library/utils/R/Sweave.R?

            val <- as.character(eval(parse(text=cmd), envir=.GlobalEnv))

i.e.

            val <- format(eval(parse(text=cmd), envir=.GlobalEnv))

I guess this would not affect Sweave users, unless they really want 12
digits in the output (e.g. the standard error is 0.123456789012).
Since format() can respect getOption('digits'), it will be much easier
to control the number of digits globally.

Regards,
Yihui
--
Yihui Xie <xieyihui at gmail.com>
Phone: 515-294-2465 Web: http://yihui.name
Department of Statistics, Iowa State University
2215 Snedecor Hall, Ames, IA



On Fri, Nov 19, 2010 at 2:02 AM, Dieter Menne
<dieter.menne at menne-biomed.de> wrote:
>
>
> Yihui Xie-2 wrote:
>>
>>
>> Currently Sweave does not format the (especially numeric) value in
>> \Sexpr{}, and I often have to round() the numbers explicitly,
>> otherwise I will get more than 10 digits, which is not necessary for
>> me in most cases. Is there a way to specify the number of digits to be
>> kept for values in \Sexpr{}? e.g. can we make \Sexpr{} respect
>> getOption('digits')?
>>
>>
>
> Currently, Sweave does an eval on Sexpr, and that can be anything other than
> a number (is mostly is, though). And you cannot define a new version of
> Sexpr in latex, because Sexpr only looks like latex, but is processed before
> texing.
>
> My solution is to always do the rounding and formating in the R chunk (e.g.
> with latexSN of Hmisc) to unclutter the Sexpr.
>
> Dieter
>
>



More information about the R-help mailing list