rquine

Constructing quines (self-reproducing functions)


Has anyone constructed a quine ("A program that generates a copy of its own source text as its complete output": http://www.nyx.net/~gthompso/quine.htm) in R? (The [quine] tag pulls up lots of examples in Python, Java, ... but apparently none in R.)

f <- function() { body() }

comes close:

> f()
{
    body()
}

but lacks the name of the function.

How about the shortest possibility? Most obfuscated?

edit: from the variety of answers below, it seems that there are a variety of ways to define self-referentiality and the environment in which it must occur:

Notes:


Solution

  • This is the shortest I can come up with:

    > "f" <- function() call("<-", "f", f)
    > f()
    "f" <- function () 
    call("<-", "f", f)