Some additional notes:
1) You can disable this function with options(keep.source=FALSE) (default is TRUE ):
> as.list(substitute(function(x = 1){x^2})) [[1]] `function` [[2]] [[2]]$x [1] 1 [[3]] { x^2 } [[4]] NULL
In this list first element is the character that identifies the closure object, the second saves the formals , and the third saves the body . Please note that this last one is printed in the standard way. The fourth element would save the input text as indicated.
2) If you type function(x = 1){x^2} on the console, R calls print.function , which takes the useSource argument. By default, this is TRUE and causes R to simply repeat what is stored in the fourth element of the parsing list. Setting it to FALSE causes R to print the body function:
> options(keep.source=TRUE) > f <- function(x = 1){x^2} > f function(x = 1){x^2} > print.function(f) function(x = 1){x^2} > print.function(f, useSource=FALSE) function (x = 1) { x^2 }
source share