missing_arg {gbutils} | R Documentation |
Check if an element of a pairlist is missing
Description
Check if an element of a pairlist is missing.
Usage
missing_arg(arg)
Arguments
arg |
the object to test. |
Details
The argument passed to missing_arg
is typically an element of a
pairlist
or the list produced by alist()
. missing_arg
returns TRUE
if it is missing and FALSE
otherwise.
Objects of type pairlist
come up at R level almost exclusively
as the formal arguments of functions. missing_arg
can be useful
when they are manipulated programmatically.
Value
TRUE or FALSE
Author(s)
Georgi N. Boshnakov
Examples
lmargs <- formals(lm)
class(lmargs) # pairlist
missing_arg(lmargs$data)
## which arguments of lm() have no (explicit) defaults?
sapply(lmargs, missing_arg)
## This gives an error:
## pairlist(x = 3, y = , z = 5)
## an example with alist()
pl2 <- alist(a = "", b = , c = 3)
class(pl2) # list
## this shows that 'b' is missing, 'a' and 'c' are not:
sapply(pl2, missing_arg) # FALSE TRUE FALSE
## superficially, 'b' is equal to the empty string:
pl2[[2]]
sapply(pl2, function(x) x == "") # TRUE TRUE FALSE
## with pairlist the results are the same:
g <- function(a = "", b, c = 3) NULL
a.g <- formals(g)
class(a.g) # pairlist
sapply(a.g, missing_arg) # FALSE TRUE FALSE
a.g[[2]]
sapply(a.g, function(x) x == "") # TRUE TRUE FALSE
[Package gbutils version 0.5 Index]