Skip to main content

Module logical

Module logical 

Source
Expand description

Logical type conversions (Rboolean, bool, Option variants).

LGLSXP literals here are the source of truth (#882). bool/Rboolean are deliberately not RNativeType — R logical vectors are stored as i32 (that’s RLogical), and these impls translate the three-state TRUE/FALSE/NA LGLSXP payload into a two-state Rust bool. There is no T::SEXP_TYPE to derive the tag from for bool; the literal is the boundary, leave it.

Handles the three R logical states (TRUE, FALSE, NA) and maps them to Rust:

Rust TypeNA Handling
RbooleanError on NA
boolError on NA
Option<Rboolean>None on NA
Option<bool>None on NA

§Tradeoff

Use Option<bool> / Option<Rboolean> if R might pass NA — the plain bool / Rboolean impls treat NA as a conversion failure. Failure mode of binding a plain bool when callers can pass NA: every NA argument surfaces as SexpNaError at the call site, which is usually not what you want for an interactive R API.

The optional native scalars live here too: Option<i32>, Option<f64>, Option<u8> and Option<Rcomplex> read NULL, their own type’s NA (raw has none) and a plain NA, R’s untyped missing value, as None (#2305, is_null_or_plain_na). A logical NA is already None for the logical forms.

Outbound counterpart: bool / Option<bool> impls in crate::into_r.

Re-exports§

use crate::from_r::SexpError; 🔒
use crate::from_r::SexpNaError; 🔒
use crate::from_r::TryFromSexp; 🔒
use crate::from_r::is_null_or_plain_na; 🔒
use crate::from_r::is_null_or_plain_na_unchecked; 🔒
use crate::IsNA; 🔒
use crate::IsNA; 🔒
use crate::RLogical; 🔒
use crate::Rboolean; 🔒
use crate::SEXP; 🔒
use crate::SEXPTYPE; 🔒
use crate::SexpExt; 🔒