R-alpha: Re: .Options$digits do not (always) work

Kurt Hornik Kurt.Hornik@ci.tuwien.ac.at
Mon, 25 Aug 1997 08:51:44 +0200


While trying to understand official and private explanations of Robert
and Martin before writing something useful in the FAQ, I did some more
experimenting ...

Please have a look at the following.  According to Martin, this is also
what he observed about 2 weeks ago but did not document exactly enough
when posting.

Note:  the explanation given by Robert was (roughly speaking) that the
result of options()$digits is used for printing, and NOT the value of
.Options$digits.

Here it comes.

***********************************************************************
R> .Options$digits
[1] 7

R> tst2 <- function(x=pi, dig =3) {
+   oo <- options(digits=dig); on.exit(options(oo)); print(x);x}
R> tst2()
[1] 3.14
[1] 3.141593
R> tst2(dig = 12)
[1] 3.14159265359
[1] 3.141593
***********************************************************************

Up to here, everything is fine and rational.  But now:

***********************************************************************
R> .Options$digits <- 5

R> tst2()
[1] 3.1416
[1] 3.1416
R> tst2(dig = 12)
[1] 3.1416
[1] 3.1416
***********************************************************************

Oops, the internal value of options()$digits is ignored .... Really?
Let's test:

***********************************************************************
R> tst3 <- function(x=pi, dig =3) {
+ oo <- options(digits=dig); on.exit(options(oo));
+ print(c(.Options$digits, options()$digits)); print(x); x }
R> tst3()
[1] 5 3
[1] 3.1416
[1] 3.1416
R> tst3(dig = 12)
[1]  5 12
[1] 3.1416
[1] 3.1416

R> tst4 <- function(x=pi, dig =3) {
+ .Options$digits <- dig;
+ print(c(.Options$digits, options()$digits)); print(x); x }
R> tst4()
[1] 3 7
[1] 3.1416
[1] 3.1416
***********************************************************************

SUMMARY:  If we assign explicitly to .Options$digits in .GlobalEnv,
there is NO WAY we can change the print behavior inside functions after
that, neither by assigning to .Options$digits nor by using
options(digits = ...).

Surely, this cannot be a feature!

-k
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-devel-request@stat.math.ethz.ch
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-