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)
| x | A logical vector |
|---|
An integer vector
#> [1] 1 0 2# }