Quantcast
Channel: Active questions tagged r - Stack Overflow
Viewing all articles
Browse latest Browse all 201894

Why names() function does not show up in sys.calls() output stack - R

$
0
0

I defined the following function in R to test the output of sys.calls(), a function that returns the function calling stack:

show_syscall_stack = function() {
  print(sys.calls())
  invisible(list(x=2, y=3))
}

I observed the following two behaviours:

1) Calling names() on the output of this function does not show names() as part of the function calling stack

Interestingly enough, when I run:

names(show_syscall_stack())

I get the following output (where the names() function does not appear as part of sys.calls()'s returned value):

[[1]]
show_syscall_stack()

[1] "x""y"

2) Calling ls() on the output of this function does show ls() as part of the function calling stack (as expected)

Instead when I run:

ls(show_syscall_stack())

I get the following output (where the ls() function does appear in the stack returned by sys.calls()):

[[1]]
ls(show_syscall_stack())

[[2]]
tryCatch(name, error = function(e) e)

[[3]]
tryCatchList(expr, classes, parentenv, handlers)

[[4]]
tryCatchOne(expr, names, parentenv, handlers[[1L]])

[[5]]
doTryCatch(return(expr), name, parentenv, handler)

[[6]]
show_syscall_stack()

[1] "x""y"

I would like to understand if:
a) this behaviour happens because names() is a primitive function (see ?names).
b) primitive functions fall into the concept of "contexts", to which sys.calls() does not have access as mentioned in the following paragraph of ?sys.calls (Details section):

Notice that even though the sys.xxx functions (except sys.status) are interpreted, their contexts are not counted nor are they reported. There is no access to them.


My platform:

R version 3.5.2 (2018-12-20)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)

Viewing all articles
Browse latest Browse all 201894

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>