R-alpha: missing()

Ross Ihaka (ihaka@stat.auckland.ac.nz)
Thu, 12 Sep 1996 14:36:09 +1200

Date: Thu, 12 Sep 1996 14:36:09 +1200
From: Ross Ihaka <ihaka@stat.auckland.ac.nz>
Message-Id: <199609120236.OAA27042@stat.auckland.ac.nz>
To: r-testers@stat.math.ethz.ch
Subject: R-alpha: missing()

Here is an example from S:

	Version 3.3 Release 1 for Sun SPARC, SunOS 4.1.x : 1995 
	Working data will be in /users/rdev/ihaka/.Data 
	> f <- function(x) missing(x)
	> g <- function(x) f(x)         
	> f()
	[1] T
	> g()
	[1] F

This indicates that missingness does indeed not propagate downwards and
as Doug Bates points out it is the responsibility of a called function
to check any arguments it has for missingness before passing them on
as arguments to other functions.

The exception to this would seem to be NextMethod which is almost
certainly practicing some very black magic and should probably not
be regarded as a real function call.

In R, Robert has implemented NextMethod as a regular (interpreted)
function (it also dabbles in the black arts to some extent).  Because
of this, we have no choice but to propagate missingness.  This is done
only for arguments which are handed on though function calls without

For example in R:

	> f <- function(x) missing(x)
	> g1 <- function(z) f(z)
	> g2 <- function(z) f(z+1)
	> f()
	[1] TRUE
	> g1()
	[1] TRUE
	> g2()
	[1] FALSE

In g1() the missingness of z is propagated down, but since z+1 is
not a formal argument in g2(), it does not have any missingness to
pass down.

The use of missing also differs for R because R is lexically scoped.
Thus if f() is defined by

	f <- function(x) {
		g <- function(y) missing(x)
then in S we get

	> f()
	Error in g(): Object "x" not found

whereas in R we get

	> f()
	[1] TRUE

this is because in R, the formal parameter "x" of f() is visible in the
body of g(), whereas in S it is not.

r-testers mailing list -- To (un)subscribe, send
subscribe	or	unsubscribe
(in the "body", not the subject !)  To: r-testers-request@stat.math.ethz.ch