| Title: | Parse Compact Numbers in Chinese Data |
|---|---|
| Description: | Parses compact numeric values, qualified quantities, and ranges commonly found in Chinese tables and spreadsheets. It handles Chinese magnitude suffixes, currencies, percentages, full-width characters, financial negatives, and configurable missing-value markers while reporting values that cannot be parsed safely. |
| Authors: | Haotian Liu [aut, cre, cph] |
| Maintainer: | Haotian Liu <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 0.2.14 |
| Built: | 2026-10-16 01:39:09 UTC |
| Source: | https://github.com/jorungandr/cncleanr |
Returns parsing failures attached to an object produced by a cncleanr
parser. Successful results return an empty data frame with the same stable
schema.
Use cn_subset() to select or reorder rows with their diagnostics. Other
base R transformations may drop the attribute or retain stale indices.
cn_problems(x)cn_problems(x)
x |
An object returned by a cncleanr parsing function. |
A data frame with columns index, value, and reason.
result <- suppressWarnings(parse_cn_number(c("bad", "2\u4e07"))) cn_problems(result)result <- suppressWarnings(parse_cn_number(c("bad", "2\u4e07"))) cn_problems(result)
Explicitly subsets or reorders an unmodified parser result and remaps its
problem indices to positions in the selected result. Repeated selections
repeat the corresponding problems. Ordinary [ does not track problems.
cn_subset(x, rows)cn_subset(x, rows)
x |
An unmodified result from a cncleanr parser, or from |
rows |
Integer-valued numeric indices (positive, zero, or negative using
base R rules), or a logical vector of exactly the input length/row count.
Missing, nonfinite, fractional and out-of-range indices are rejected.
Defaults to all rows. Use |
Call this before other transformations. It cannot recover problems lost or made stale by ordinary subsetting, mutation, sorting or binding. It does not reparse values or emit another parsing warning.
The selected numeric vector or data frame, without a new class. Problem indices refer to the selected result, not the original input.
result <- suppressWarnings(parse_cn_number(c("bad", "2", "wrong"))) selected <- cn_subset(result, c(3, 2, 1, 3)) cn_problems(selected) cn_subset(result, !is.na(result))result <- suppressWarnings(parse_cn_number(c("bad", "2", "wrong"))) selected <- cn_subset(result, c(3, 2, 1, 3)) cn_problems(selected) cn_subset(result, !is.na(result))
Converts character values such as "1.25\u4e07", "\uffe53\u4ebf",
"1.2e5", and "12.5%"
to doubles. Parsing is deliberately conservative: every non-missing value
must match the supported syntax in full. Spaces between digits are accepted
only when they form valid three-digit grouping.
parse_cn_number( x, na = c( "", "NA", "N/A", "\u6682\u65e0", "\u672a\u516c\u5e03", "\u2014", "\u2013", "-", "...", "\u2026" ), strict = FALSE, unit = NULL )parse_cn_number( x, na = c( "", "NA", "N/A", "\u6682\u65e0", "\u672a\u516c\u5e03", "\u2014", "\u2013", "-", "...", "\u2026" ), strict = FALSE, unit = NULL )
x |
A character, factor, or numeric vector. When |
na |
A character vector containing values that should be interpreted as missing. Matching happens after whitespace and full-width normalization. |
strict |
A single logical value. If |
unit |
A single optional table-header unit: yuan, thousand yuan,
ten thousand, hundred million, or trillion, optionally in yuan. Use the
spellings |
Finite-range validation applies to parsed character and factor
input. With unit = NULL, existing numeric Inf, -Inf, and NaN
values are preserved.
Results use double precision, not exact integer or decimal arithmetic.
Nonzero character values rounded to zero after final unit conversion are
reported as underflow; representable subnormal values are retained.
A double vector with the same length and names as x. When invalid
values occur in non-strict mode, the result has a problems attribute with
columns index, value, and reason.
parse_cn_number(c("1.25\u4e07", "3\u4ebf\u5143", "12.5%", "\u6682\u65e0")) parse_cn_number(c("\uff11\uff12\uff0e\uff15\uff05", "(2.5\u4e07)")) parse_cn_number(c("123.5", "1.5\u5343\u5143"), unit = "\u5343\u5143")parse_cn_number(c("1.25\u4e07", "3\u4ebf\u5143", "12.5%", "\u6682\u65e0")) parse_cn_number(c("\uff11\uff12\uff0e\uff15\uff05", "(2.5\u4e07)")) parse_cn_number(c("123.5", "1.5\u5343\u5143"), unit = "\u5343\u5143")
Parses exact values and values qualified by language or symbols, such as
"\u7ea63\u4e07", "\u5927\u4e8e2\u4ebf", "\u4e0d\u5c0f\u4e8e5\u4e07", "10\u4e07+", "50\u4f59", or
"50\u4f59\u4e07\u5143".
The qualifier is retained instead of silently discarded.
One approximation prefix combined with an approximation suffix is accepted,
for example "\u7ea615%\u5de6\u53f3". Repeated prefixes or suffixes and
mixed inequality qualifiers are rejected.
parse_cn_quantity( x, na = c( "", "NA", "N/A", "\u6682\u65e0", "\u672a\u516c\u5e03", "\u2014", "\u2013", "-", "...", "\u2026" ), strict = FALSE )parse_cn_quantity( x, na = c( "", "NA", "N/A", "\u6682\u65e0", "\u672a\u516c\u5e03", "\u2014", "\u2013", "-", "...", "\u2026" ), strict = FALSE )
x |
A character, factor, or numeric vector. Numeric input is converted
to double and otherwise passed through unchanged, including |
na |
A character vector containing values that should be interpreted as missing. Matching happens after whitespace and full-width normalization. |
strict |
A single logical value. If |
A data frame with double column value and character column
qualifier. Qualifiers are exact, approx, greater_than, at_least,
less_than, and at_most. Numeric finite and infinite values have the
qualifier exact; NA and NaN have a missing qualifier. Numeric values,
including Inf, -Inf, and NaN, are preserved in value.
parse_cn_quantity(c( "\u7ea63\u4e07", "\u5927\u4e8e2\u4ebf", "10\u4e07+", "50\u4f59", "50\u4f59\u4e07\u5143" ))parse_cn_quantity(c( "\u7ea63\u4e07", "\u5927\u4e8e2\u4ebf", "10\u4e07+", "50\u4f59", "50\u4f59\u4e07\u5143" ))
Converts closed ranges such as "3\u4e07-5\u4e07" and open bounds such as
"10\u4e07\u5143\u4ee5\u4e0a" into explicit lower and upper bounds. A shared suffix in
"3-5\u4e07" is applied to both endpoints. Signs used by negative numbers and
scientific notation are distinguished from range separators.
Digit grouping is validated independently at each range endpoint, so
"1 234-2 345" is accepted but "1 23-2 345" is not.
Endpoint missing markers are checked before and after shared-unit propagation.
parse_cn_range( x, na = c( "", "NA", "N/A", "\u6682\u65e0", "\u672a\u516c\u5e03", "\u2014", "\u2013", "-", "...", "\u2026" ), strict = FALSE )parse_cn_range( x, na = c( "", "NA", "N/A", "\u6682\u65e0", "\u672a\u516c\u5e03", "\u2014", "\u2013", "-", "...", "\u2026" ), strict = FALSE )
x |
A character, factor, or numeric vector. Numeric input is converted
to double and otherwise passed through unchanged, including |
na |
A character vector containing values that should be interpreted as missing. Matching happens after whitespace and full-width normalization. |
strict |
A single logical value. If |
A data frame with columns lower, upper, lower_inclusive, and
upper_inclusive. Numeric input becomes an inclusive point range,
including numeric Inf and -Inf; NA and NaN have missing
inclusivity. Infinite bounds created from textual inequalities represent
open-ended bounds and are distinct from numeric point inputs.
parse_cn_range(c("3\u4e07-5\u4e07", "3-5\u4e07", "10\u4e07\u5143\u4ee5\u4e0a"))parse_cn_range(c("3\u4e07-5\u4e07", "3-5\u4e07", "10\u4e07\u5143\u4ee5\u4e0a"))