Remove elements from a vector or list that are considered "void":
NA
, NULL
, and empty strings (""
). Each can be toggled via parameters.
Usage
drop_void(x, include_na = TRUE, include_null = TRUE, include_empty_str = TRUE)
Arguments
- x
A vector or list.
- include_na
Logical. Remove NA
if TRUE. Default: TRUE.
- include_null
Logical. Remove NULL
if TRUE. Default: TRUE.
- include_empty_str
Logical. Remove ""
if TRUE. Default: TRUE.
Value
A cleaned vector or list of the same type as input, with void values removed.
Examples
drop_void(c("apple", "", NA, "banana"))
#> [1] "apple" "banana"
drop_void(list("A", NA, "", NULL, "B"))
#> [[1]]
#> [1] "A"
#>
#> [[2]]
#> [1] "B"
#>
drop_void(c("", NA), include_na = FALSE)
#> [1] NA