ecotyper.rcompat.parse

Text → double conversion exactly as R does it.

R does not use the C library’s (correctly rounded) strtod:

  • read.delim/read.table/scan → type.convert → R_strtod5 (src/main/util.c): digits accumulated with ans = 10*ans + d (an FMA on arm64) and then divided by a power of ten built by repeated squaring, so values with more than ~22 decimal places of scale are not always correctly rounded.

  • data.table::fread → parse_double_regular (fread.c): 64-bit integer mantissa, then one multiplication/division by a tabulated 10^k.

EcoTyper’s scripts exchange data through text files, so reproducing R’s numbers bit for bit requires the same parsers. read_numeric_table() parses a tab-delimited numeric table in either mode.

Functions

r_parse(values[, mode])

Parse an iterable of strings with R's (or fread's) number parser.

read_numeric_table(path[, mode])

Parse a tab-delimited table whose first column holds names.

text_roundtrip(x[, mode])

Values as R sees them after write.table (15 significant digits) and re-reading with read.delim (mode="r") or fread.

ecotyper.rcompat.parse.read_numeric_table(path, mode='r')[source]

Parse a tab-delimited table whose first column holds names.

Returns (header, first_col, values); header holds every header field (including the first-column name when present). mode is "r" (read.delim) or "fread".

Parameters:

mode (str)

ecotyper.rcompat.parse.r_parse(values, mode='r')[source]

Parse an iterable of strings with R’s (or fread’s) number parser.

Parameters:

mode (str)

Return type:

ndarray

ecotyper.rcompat.parse.text_roundtrip(x, mode='r')[source]

Values as R sees them after write.table (15 significant digits) and re-reading with read.delim (mode="r") or fread.

Parameters:
Return type:

ndarray