BoolToInt: Convert a logical to an integer

View source: R/zzz.R

BoolToIntR Documentation

Convert a logical to an integer

Description

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

Usage

BoolToInt(x)

Arguments

x

A logical vector

Value

An integer vector

See Also

integer logical NA WriteH5Seurat

Examples


SeuratDisk:::BoolToInt(x = c(TRUE, FALSE, NA))



mojaveazure/seurat-disk documentation built on Nov. 5, 2023, 9:40 a.m.