Does anybody know why calls such as sys.call() behave differently when called within a package compared to when the call is run natively.
For example, if I define a function:
get_call <- function() print(sys.call())
And then call that from within a function, say:
run_me <- function(){
y <- get_call()
}
The result when run within R will be:
> run_me()
y <- get_call()
However, if I create a package and put these functions inside it:
> mypkg:::run_me()
get_call()
When ran from within a package, we lose the <- part of the output.
The output from sys.call() returns a call with an attribute srcref when it is ran natively, but this doesn't appear when it is run from within a package. When it's printed, it calls print.srcref() which is why the <- appears, rather than calling the default printing function otherwise. But I don't understand why this srcref appears at all.
If the package is loaded via devtools::load_all(), it still shows as the native version above. load_all() creates a kind of faux-namespace by loading all of the functions in the package directory into a new environment and then adds it on the search() path. Which is different to actually loading a package, where the package is built first. So there must be something within this building process that isn't affixing this srcref attribute, that does get attached when the function/call is built natively. Worth noting that sys.function() also gives an srcref.