The default print()
method prints the source if available (from a srcref attribute) for expression objects, but not for calls. See below for an example (run in R 3.3.1).
It looks like this change has been introduced in R 2.10.0, in revision r48366 [2], but it hasn't been documented explicitly. I'm wondering if calls should use an attached srcref for printing. For now, deparse
uses the class "srcref_call"
with an overridden print()
method.
text <- "a(\n)" text ex <- parse(text = text, srcfile = srcfilecopy("dump.R", text))
Returns an "expression", it uses the srcref for printing
ex
attributes(ex)
cl <- ex[[1]] attr(cl, "srcref") <- attr(ex, "srcref")[[1]] attr(cl, "srcfile") <- attr(ex, "srcfile") attr(cl, "wholeSrcref") <- attr(ex, "wholeSrcref")
The call does not use the srcref for printing
cl
print.call <- function(x, ..., useSource = TRUE) { print(attr(x, "wholeSrcref"), ...) }
Now works as expected
print(cl)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.