Skip to content

R-alpha: R 0.50.a1 problem

2 messages · Kurt Hornik, Peter Dalgaard

#
Here's something really strange.

********************************************************
R> x <- 1:5
R> x
[1] 1 2 3 4 5

R> test1
function (x) 
{
        structure(x, call = sys.call())
}
R> test1(x)
[1] 1 2 3 4 5
attr(,"call")
test1(x)

R> test2
function (x) 
{
        attr(x, "call") <- sys.call()
        x
}
R> test2(x)
Error: stack overflow
********************************************************

Using the attr() form results in an endless loop ...

-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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
Kurt Hornik <hornik@ci.tuwien.ac.at> writes:
Sounds familiar. The "assignment causes evaluation effect". Hey,
here's an amusing variant:
attr(x,"junk")<-cll;x}
function () 
{
        cll <- substitute(ls())
        print(cll)
        x <- 1
        attr(x, "junk") <- cll
        x
}
ls()
[1] 1
attr(,"junk")
[1] "*tmp*" "cll"   "x"
function () 
{
        cll <- substitute(ls())
        print(cll)
        x <- structure(1, junk = c("*tmp*", "cll", "x"))
        attr(x, "junk") <- cll
        x
}
...I know that R is a functional programming language and that
functions can write and modify other functions, but this seems to be
overdoing it a bit, donchathinkso <evil grin>?