R-alpha: "invisible" : R_INVISIBLE .. -- repeat{} gives BOMB
Martin Maechler
Martin Maechler <maechler@stat.math.ethz.ch>
Thu, 6 Nov 1997 11:55:17 +0100
>>>>> "Martyn" == Martyn Plummer <plummer@iarc.fr> writes:
Martyn> maechler@stat.math.ethz.ch wrote:
>> Try this (all versions of R from 0.49 to 0.60):
>>
>> test0 <- function() c(1,2) test <- function(two = FALSE) c(1,
>> if(two) 2) testR <- function(two = FALSE) return(c(1, if(two) 2))
>>
>> test0()# 1 2 as it should test() # <<<<<<<<<<<<<<<<<<<<<< INVISIBLE!
>> @#$@! test(T)# 1 2 print(test()) print(test(T))
>>
>> testR() # ok; NOT invisible... testR(T)# 1 2
Martyn> The problem seems to be in do_if (eval.c) where the R_Visible
Martyn> flag is set to 0. Set it to 1 instead and your functions will
Martyn> work properly. You also get
R> if(F) 2
Martyn> NULL
Martyn> instead of
R> if(F) 2
R>
Martyn> which is consistent with S-PLUS.
Wow, this was quick and precise, thank you !!
I investigated some more:
R_VISIBLE is set to 0 ``R_Visible = 0;''
also in other places in eval.c :
line C function
344: do_if
436: do_for
480: do_while
515: do_repeat
720: \
727: > do_set
738: /
^^^
(line numbers from current 0.60)
In my opinion, only the three cases in do_set ("<-" things) should have
the invisibility flag...
testwh <- function(n = 1) c(1, while(n > 1) {n <- n-1; n})
testwh() # invisible !
testwh(2)
print(testwh()) # 1
print(testwh(2))# 1 1
##-- in Splus, both are visible
###-------- THIS IS EVEN WORSE: Segmentation violation !!! -----
testrep <- function(n = 1) c(1, repeat {n <- n-1; if(n<=0) break})
testrep()
##R : Process R:1 segmentation violation at Thu Nov 6 11:36:27 1997
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=