Skip to main content

Module as_numeric

Module as_numeric 

Source
Expand description

AsNumeric / AsNumericVec: a number argument read the way R’s as.numeric() reads it, from numbers, text, or factor labels. The reading rules are documented on AsNumericVec.

Re-exportsΒ§

use crate::from_r::BatchedErrors; πŸ”’
use crate::from_r::SexpError; πŸ”’
use crate::from_r::SexpLengthError; πŸ”’
use crate::from_r::SexpTypeError; πŸ”’
use crate::from_r::TryFromSexp; πŸ”’
use crate::from_r::charsxp_to_cow_lossy; πŸ”’
use crate::from_r::impl_option_try_from_sexp; πŸ”’
use crate::from_r::map_strsxp_with; πŸ”’
use crate::from_r::try_charsxp_to_str; πŸ”’
use crate::into_r::IntoR; πŸ”’
use crate::IsNA; πŸ”’
use crate::IsNA; πŸ”’
use crate::RLogical; πŸ”’
use crate::SEXP; πŸ”’
use crate::SEXPTYPE; πŸ”’
use crate::SexpExt; πŸ”’

StructsΒ§

AsNumeric
A numeric scalar read like R’s as.numeric(): from a double, integer, logical, character, or factor (by its labels) of length 1. NA of any type is None.
AsNumericVec
A numeric vector read like R’s as.numeric(): from a double, integer, logical, character, or factor (by its labels) vector. NA of any type is None.
NotNumeric πŸ”’
A value that as.numeric() would turn into NA with a coercion warning.

FunctionsΒ§

check_type πŸ”’
Refuse every SEXPTYPE the markers do not read. REALSXP is named as the expected type because that is the storage the value ends up in.
finish πŸ”’
Return the values, or the one batched error naming every rejected element.
is_blank πŸ”’
R’s isBlankString: empty, or only blank characters.
is_blank_char πŸ”’
Whether c counts as blank for R’s isBlankString, which uses iswspace in a UTF-8 locale: Unicode whitespace except NEL (U+0085) and the no-break spaces U+00A0, U+2007 and U+202F, which neither glibc nor macOS classes as space.
is_na_token πŸ”’
The missing-value token "NA", with blanks around it at most.
level_label πŸ”’
The text of level k (0-based) of a factor’s levels STRSXP.
parse_charsxp πŸ”’
Parse one CHARSXP the way as.numeric() does.
parse_nul_terminated πŸ”’ ⚠
Parse s as R’s RealFromString does, plus the "NA" token.
read_factor_labels πŸ”’
Read a factor by its labels: each level is parsed once, then every code looks its level up. Code NA is None; a code outside the levels is a malformed factor (R’s as.character() refuses it too).
read_numeric πŸ”’
Read any accepted input into Vec<Option<f64>>, collecting every non-numeric element into one error.
refused_by_no_na πŸ”’
Whether #[miniextendr(no_na)] refuses a value the markers read: None (every kind of NA, the text "NA", a blank string) and NaN (also read from the text "NaN"), as R’s anyNA() refuses a numeric NaN.
rest_is_blank πŸ”’
Whether the bytes R_strtod left unread are blank. They follow an ASCII prefix of a valid UTF-8 string, so a failed UTF-8 check only happens for a split multi-byte character, which is not blank either.

Type AliasesΒ§

Rejected πŸ”’
The rejected-element accumulator: 0-based index and the offending text.