is.null()

is.null(x)
Returns: logical · Updated March 13, 2026 · Base Functions
null type-checking base

The is.null() function tests whether an object is NULL. NULL represents the absence of a value in R.

Syntax

is.null(x)

Parameters

ParameterTypeDefaultDescription
xany objectObject to test for NULL

Examples

Basic usage

# NULL object
x <- NULL
is.null(x)
# [1] TRUE

# Non-NULL objects
y <- NA
is.null(y)
# [1] FALSE

z <- 1
is.null(z)
# [1] FALSE

NULL vs NA

# Important: NA is not NULL
is.null(NA)
# [1] FALSE

is.na(NA)
# [1] TRUE

# NULL in vectors
vec <- c(1, 2, NULL, 4)
is.null(vec)
# [1] FALSE

# NULL is removed when creating vectors
c(1, 2, NULL, 4)
# [1] 1 2 4

Common Patterns

Setting default values

# Function with NULL default
my_function <- function(x = NULL) {
  if (is.null(x)) {
    x <- "default"
  }
  x
}

my_function()
# [1] "default"

my_function("custom")
# [1] "custom"

Conditional initialization

# Initialize if not exists
if (is.null(my_variable)) {
  my_variable <- initialize_value()
}

Checking function arguments

process <- function(data, options = NULL) {
  if (is.null(options)) {
    options <- list()  # Use empty list as default
  }
  # Process with options
}

See Also