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.
Changing get_call():
get_call <- function() print(attributes(sys.call()))
and re-running/re-installing gives
> run_me()
$srcref
y <- get_call()
>mypkg:::run_me()
NULL