Unlike most programming languages, R has three possible logical (boolean) values: TRUE, FALSE, and NA; moreover, the NA value has representations in other data types, such as NA_integer_, NA_real_, and NA_character_. Simply writing out the logical values to an HDF5 file would cause issues when trying to read the data in to another language, such as Python. To encode these three logical values for other languages, we can encode the logicals as integers:

  • FALSE becomes 0L

  • TRUE becomes 1L

  • NA becomes 2L

This encoding scheme allows other languages to handle NAs in their own manner while preserving all three logicals for R

BoolToInt(x)

Arguments

x

A logical vector

Value

An integer vector

See also

integer logical NA WriteH5Seurat

Examples

# \donttest{ SeuratDisk:::BoolToInt(x = c(TRUE, FALSE, NA))
#> [1] 1 0 2
# }