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.

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