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

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Wed, 13 Aug 1997 12:37:03 +0200

>>>>> "Robert" == Robert Gentleman <rgentlem@stat.auckland.ac.nz> writes:

    Robert> Martin wrote:
    >> I am sorry that this IS an old topic.  Yet another task I think the
    >> bug is somewhere in hidden in src/main/options.c ..
    >> ##-- The following does not work as it should in R (0.50-a1, but I
    >> think also earlier)
    >> tst <- function(x=pi, dig =3) {.Options$digits <- as.integer(dig);
    >> print(x);x} tst() tst(dig = 12)
    >> ##-- This should do the same; it works as expected in R & S :
    >> tst2 <- function(x=pi, dig =3) { oo <- options(digits=dig);
    >> on.exit(oo); print(x);x} tst2() tst2(dig = 12)

    Robert>   Well it isn't really clear what Splus does to get tst to
    Robert> work. It appears that they use some form of dynamic scope for
    Robert> Options. Clearly, the assignment, .Options$digits<- xxxx
    Robert> creates a local copy of .Options and changes the value of
    Robert> that. The only way that print can find this local copy is if it
    Robert> looks up the stack of calling functions to find it (or perhaps
    Robert> Splus squirrels it away somewhere that print looks but then <-
    Robert> starts to behave in a very peculiar manner).  This sort of
    Robert> behaviour is bad for two reasons 1) We really want people to
    Robert> use lexical scope and any examples where you have dynamic scope
    Robert> simply confuse things 2) It is quite inefficient for print (and
    Robert> anything else that uses Options) to have to look up the stack
    Robert> of calling functions.

yes, I wonder too, how S-plus does it. (Bill V. ?)
    Robert>   Since the method Martin so capably demonstrated with tst2
    Robert> does work (except I think he meant on.exit(options(oo)) rather
    Robert> than on.exit(oo)) I think we should stick with that. In that
    Robert> case the global value of options(digits) is changed for the
    Robert> duration of the function evaluation of tst2.
okay, I could live with it.

Problem is:

	In the current version (i.e. 0.50-a3), even  tst2(.)
	does NOT work !
	(yes, it did before ..)

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