These functions help using the missing argument as a regular R object. It is valid to generate a missing argument and assign it in the current environment or in a list. However, once assigned in the environment, the missing argument normally cannot be touched. maybe_missing() checks whether the object is the missing argument, and regenerate it if needed to prevent R from throwing a missing error. In addition, is_missing() lets you check for a missing argument in a larger range of situations than base::missing() (see examples).

missing_arg()

is_missing(x)

maybe_missing(x)

## Arguments

x An object that might be the missing argument.

## Examples

# The missing argument can be useful to generate calls
quo(f(x = !! missing_arg()))#> <quosure: local>
#> ~f(x = )quo(f(x = !! NULL))#> <quosure: local>
#> ~f(x = NULL)

# It is perfectly valid to generate and assign the missing
# argument.
x <- missing_arg()
l <- list(missing_arg())

# Note that accessing a missing argument contained in a list does
# not trigger an error:
l[[1]]#> is.null(l[[1]])#> [1] FALSE
# But if the missing argument is assigned in the current
# environment, it is no longer possible to touch it. The following
# lines would all return errors:
#> x
#> is.null(x)

# In these cases, you can use maybe_missing() to manipulate an
# object that might be the missing argument without triggering a
# missing error:
maybe_missing(x)#> is.null(maybe_missing(x))#> [1] FALSEis_missing(maybe_missing(x))#> [1] TRUE

# base::missing() does not work well if you supply an
# expression. The following lines would throw an error:

#> missing(missing_arg())
#> missing(l[[1]])

# while is_missing() will work as expected:
is_missing(missing_arg())#> [1] TRUEis_missing(l[[1]])#> [1] TRUE