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

Duncan Murdoch murdoch.duncan at gmail.com
Fri Nov 19 16:24:11 CET 2010


On 19/11/2010 10:12 AM, Yihui Xie wrote:
> 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.

I don't like the current behaviour, but that change could break a lot of 
existing documents.  Since you can easily wrap your Sexpr arguments in a 
call to whatever formatting function you want, why force all of those 
users to change their documents?

Duncan Murdoch

> 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
> >
> >
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list