[R] Some Programming Humor - Quine
Barry Rowlingson
B.Rowlingson at lancaster.ac.uk
Thu May 15 15:43:37 CEST 2003
> so my quine-version seems not to pass this test:
>
>>identical(quine,quine())
>
> [1] FALSE
>
>>identical(quine(),quine()())
>
> [1] FALSE
>
> has this to do with the environment somehow being part of the function? I
> dont quite understand, since quine(), quine()(), quine()()() all look quite
> identical to me, save the information about the environment that is added
> after the return value.
>
Thats right. Even if the environment isn't printed, its still there,
and so the quine fails the 'identical' test.
If you can adjust your code to return an object with the same
environment as itself then it will work
> q2 <- quine()
> identical(q2,quine)
[1] FALSE
> environment(q2) <- environment(quine)
> identical(q2,quine)
[1] TRUE
In fact all you need to do is set the environment to globalenv(). I'm
sure a minor adjustment to your script can fix this!
Baz
More information about the R-help
mailing list