Sys.frame in Rmarkdown

In an R script:

temp = function(aParam = 1)  ls(envir=sys.frame(1))

The return value is:

[1] "aParam"

as expected.

In an Rmarkdown doc,

 temp = function(aParam = 1)  ls(envir=sys.frame(1))

the return value is a vector of 45 names starting with "base_pandoc_to".
Changing the frame number, I can't find the correct frame anywhere in the range -3 to 20.

Not a problem that can't be overcome, but I am curious to understand what's going on with sys.frame.
(Sorry for the stray dot, seems necessary to get this post to format roughly correctly.)

This works in Rmarkdown:

temp = function(aParam = 1) {
#  print(length(sys.frames()))
  theframes = sys.frames()
  numframes = length( theframes)
  fr = sys.frame(numframes)
  print (paste(" numframes ", numframes))

for which the answer is:

## [1] " numframes  19"
## [1] "aParam"    "fr"        "numframes" "theframes"