Skip to content

File > Save As...

3 messages · Duncan Murdoch, Gene Leynes

#
On 13/04/2011 5:20 PM, Gene Leynes wrote:
There's a limitation to the debug information:  it can't be attached to 
a function whose body consists of a single simple expression like 
print(a).  If you put braces around print(a), it will be attached to the 
body of x:

Put this line into a file, and source it:

x <- function(a) { print(a) }

source("test.R")
attr(body(x), "srcref")

In case you're interested, the reason for this limitation is that there 
are some objects in R (NULL is the most obvious one) which can be a 
function body but which can't hold attributes.  At the time the debug 
info is added, the function hasn't been created, but its body has, so 
the attribute has to go there.

Duncan Murdoch