| 1 |
\name{missingCh} |
| 2 |
\alias{missingCh} |
| 3 |
\title{Has a Formal Argument been Set or is it Missing?} |
| 4 |
\description{ |
| 5 |
\code{missingCh} can be used to test whether a value was specified |
| 6 |
as an argument to a function. Very much related to the standard \R |
| 7 |
function \code{\link{missing}}, here the argument is given by its |
| 8 |
name, a character string. |
| 9 |
|
| 10 |
As \code{missingCh()} calls \code{missing()}, do consider the |
| 11 |
caveats about the latter, see \code{\link{missing}}. |
| 12 |
} |
| 13 |
\usage{ |
| 14 |
missingCh(x, envir = parent.frame()) |
| 15 |
} |
| 16 |
\arguments{ |
| 17 |
\item{x}{a \code{\link{character}} string.} |
| 18 |
\item{envir}{a (function evaluation) \code{\link{environment}}, in which |
| 19 |
the variable named \code{x} is to be \dQuote{missing}.} |
| 20 |
} |
| 21 |
\value{ |
| 22 |
a \code{\link{logical}} indicating if the argument named \code{x} is |
| 23 |
\code{\link{missing}} in the function \dQuote{above}, typically the |
| 24 |
caller of \code{missingCh}, but see the use of \code{envir} in the |
| 25 |
\code{vapply} example. |
| 26 |
} |
| 27 |
\author{Martin Maechler} |
| 28 |
\seealso{ |
| 29 |
\code{\link{missing}} |
| 30 |
} |
| 31 |
\examples{ |
| 32 |
tst1 <- function(a, b, dd, ...) ## does not work an with argument named 'c' ! |
| 33 |
c(b = missingCh("b"), dd = missingCh("dd")) |
| 34 |
tst1(2)#-> both 'b' and 'dd' are missing |
| 35 |
tst1(,3,,3) |
| 36 |
## b dd |
| 37 |
## FALSE TRUE -- as 'b' is not missing but 'dd' is. |
| 38 |
|
| 39 |
Tst <- function(a,b,cc,dd,EEE, ...) |
| 40 |
vapply(c("a","b","cc","dd","EEE"), missingCh, NA, envir=environment()) |
| 41 |
Tst() |
| 42 |
## TRUE ... TRUE -- as all are missing() |
| 43 |
Tst(1,,3) |
| 44 |
## a b cc dd EEE |
| 45 |
## FALSE TRUE FALSE TRUE TRUE |
| 46 |
## ..... ..... |
| 47 |
## as 'a' and 'cc' where not missing() |
| 48 |
|
| 49 |
## Formal testing: |
| 50 |
stopifnot(tst1(), !tst1(,3,3), Tst(), |
| 51 |
Tst(1,,3, b=2, E="bar") == c(0,0,1,0,0)) |
| 52 |
## maybe surprising that this ^^ becomes 'dd' and only 'cc' is missing |
| 53 |
} |
| 54 |
\keyword{programming} |