Learn R Programming

MplusAutomation (version 1.1.1)

isEmpty: Check whether a useable function argument was provided

Description

This is a simple utility to check whether a function argument is missing, NULL, or has only NAs.

Usage

isEmpty(arg)

Value

Logical vector of length 1.

Arguments

arg

A function argument

Examples

Run this code
if (FALSE) {
f1 <- function(x) {
  if (!isEmpty(x)) return(mean(x, na.rm = TRUE))
  return(NULL)
}

f1()                 #> NULL
f1(x = NA)           #> NULL
f1(x = NULL)         #> NULL
f1(x = c(NA, 1:2))   #> 1.5
}

Run the code above in your browser using DataLab