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:
->
function (@bill_080)->
program [more or less equivalent to program ->
text]: (@kohske)->
text (@JoshUlrich, @James, problem as defined above)Notes:
identical(quine,quine())
is a good test case, although it's tricky because environments get carried along: identical(quine,quine(),ignore.environment=TRUE)
might be easier.This is the shortest I can come up with:
> "f" <- function() call("<-", "f", f)
> f()
"f" <- function ()
call("<-", "f", f)