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.

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.