missing_arg | R Documentation |
Check if an element of a pairlist is missing.
missing_arg(arg)
arg |
the object to test. |
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.
TRUE or FALSE
Georgi N. Boshnakov
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.