rlang (version 0.0.0.9000)

arg_missing: Generate or handle a missing argument

Description

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 missing() (see examples).

Usage

arg_missing()
is_missing(x)
maybe_missing(x)

Arguments

x
An object that might be the missing argument.

Examples

Run this code
# The missing argument can be useful to generate calls
tidy_quote(f(x = !! arg_missing()))
tidy_quote(f(x = !! NULL))


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

# Note that accessing a missing argument contained in a list does
# not trigger an error:
l[[1]]
is.null(l[[1]])

# 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))
is_missing(maybe_missing(x))


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

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

# while is_missing() will work as expected:
is_missing(arg_missing())
is_missing(l[[1]])

Run the code above in your browser using DataCamp Workspace