Hello,

I noticed that sys.frame treats which = 0 differently than sys.call and sys.function, and the documentation was unclear about it.

> f <- function() sys.call()
> f()
f()
> f <- function() sys.function()
> f()
function() sys.function()
> f <- function() sys.frame()
> f()
<environment: R_GlobalEnv>

sys.frame(0) always returns the .GlobalEnv, while sys.call(0) and sys.function(0) return the current call and function definition.

I offer a patch to clarify this for the uninitiated.

> sessionInfo()
R version 2.6.0 Under development (unstable) (2007-04-16 r41194)
i686-pc-linux-gnu

locale:
LC_CTYPE=en_US.UTF-8;LC_NUMERIC=C;LC_TIME=en_US.UTF-8;LC_COLLATE=en_US.UTF-8;LC_MONETARY=en_US.UTF-8;LC_MESSAGES=en_US.UTF-8;LC_PAPER=en_US.UTF-8;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=en_US.UTF-8;LC_IDENTIFICATION=C

attached base packages:
[1] "stats"     "graphics"  "grDevices" "utils"     "datasets"  "methods"
[7] "base"

Jeff
--
http://biostat.mc.vanderbilt.edu/JeffreyHorner
Index: src/library/base/man/sys.parent.Rd
===================================================================
--- src/library/base/man/sys.parent.Rd	(revision 41208)
+++ src/library/base/man/sys.parent.Rd	(working copy)
@@ -18,9 +18,9 @@
 }
 \usage{
 sys.call(which = 0)
+sys.function(which = 0)
 sys.frame(which = 0)
 sys.nframe()
-sys.function(which = 0)
 sys.parent(n = 1)
 
 sys.calls()
@@ -32,7 +32,7 @@
 }
 \arguments{
   \item{which}{the frame number if non-negative, the number of frames
-    to go back if negative.}
+    to go back if negative.(See the Details section on how 0 is handled.)}
   \item{n}{the number of generations to go back. (See the Details section.)}
 }
 \details{
@@ -42,11 +42,20 @@
   of that function are returned by \code{sys.call}, \code{sys.function}
   and \code{sys.frame} with the appropriate index.
 
-  \code{sys.call}, \code{sys.frame} and \code{sys.function} accept
+  \code{sys.call}, \code{sys.function} and \code{sys.frame} accept
   integer values for the argument \code{which}.  Non-negative values of
   \code{which} are frame numbers whereas negative values are
-  counted back from the frame number of the current evaluation.
+  counted back from the frame number of the current evaluation. 
 
+  When \code{which} is 0 (the default value), \code{sys.call} and \code{sys.function}
+  return the call and function definition of the current frame, while \code{sys.frame}
+  returns the \code{\link{.GlobalEnv}}.
+
+  \code{sys.nframe} returns an integer, the number of the current frame
+  as described in the first paragraph. Consequently, \code{sys.call()} and
+  \code{sys.function()} are equivalent to \code{sys.call(sys.nframe())}
+  and \code{sys.function(sys.nframe())}.
+
   The parent frame of a function evaluation is the environment in which
   the function was called.  It is not necessarily numbered one less than
   the frame number of the current evaluation, nor is it the environment
@@ -54,9 +63,6 @@
   number of the parent frame if \code{n} is 1 (the default), the
   grandparent if \code{n} is 2, and so on.
 
-  \code{sys.nframe} returns an integer, the number of the current frame
-  as described in the first paragraph.
-
   \code{sys.calls} and \code{sys.frames} give a pairlist of all the
   active calls and frames, respectively, and \code{sys.parents} returns
   an integer vector of indices of the parent frames of each of those
______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to