Skip to content

xfun 0.62

Latest

Choose a tag to compare

@yihui yihui released this 16 Oct 04:26
· 3 commits to main since this release
  • Added radix_id() and radix_group(): radix_id() encodes row combinations as a mixed-radix numeric code (equal rows share a code, faster than paste()); radix_group() returns a 1-based group index in first-appearance order.

  • Added rust to the internal object comment_chars (thanks, @kbvernon, #132).

  • taml_load() now parses flow arrays ([...]) correctly when elements are surrounded by spaces (e.g. [ 1, 2 ]), and keeps quoted values as strings even when they look numeric (e.g. ["1"] is "1", not 1) (thanks, @reedacartwright, #133).

  • taml_load() now understands single-quoted scalars ('' is a literal ') and the full set of YAML double-quote escape sequences (e.g. \t, \/, \e, \xNN, \uNNNN), and commas inside quoted flow-array elements are no longer treated as separators (thanks, @reedacartwright, #135).

  • tojson() is faster now: string escaping is skipped when no special characters are present, the Inf/-Inf conversion is skipped when no infinite values are present, and matrices are serialized without a per-row function call.

  • tojson() now emits each row of a single-column matrix as an array (e.g., [[1], [2], [3]]) for consistency with multi-column matrices, instead of collapsing the rows into scalars.

  • tojson() now escapes </script to <\/script in strings so the output can be safely embedded in an inline <script> block (a literal </script> would otherwise close the block early). This is still valid JSON and parses back to the original string.

  • tojson() gained an argument dict to dictionary-encode atomic vectors (and data-frame columns) with repeated values. When enabled, a vector is emitted as a runnable JavaScript expression [codes].map(i => [u][i]) (0-based codes indexing the unique values u), so repeated values are serialized once instead of per element. dict is a numeric cardinality threshold in (0, 1] (0, the default, disables it), and encoding is used only when it actually shortens the output, so near-unique vectors are left as plain arrays.

  • tojson() gained an argument pretty (TRUE by default). With pretty = FALSE, the output is compact (single line, no indentation, and , instead of , between array elements), which can be substantially smaller for large data.

  • tojson() now emits a nested json value (e.g., a value pre-serialized by tojson()) raw instead of re-quoting it as a string, so tojson() output can be composed inside a larger tojson() call.

  • tojson() gained an argument pack (and the option xfun.tojson.pack) to pack long integer vectors (and the codes of dict-encoded vectors) as base64 little-endian bytes in a small tagged object, which is smaller and much faster to parse than a number array; the new strings json_unpack (decode one packed object on demand, preferred for large data) and json_reviver (for JSON.parse(), which is slower on large data) contain JavaScript code that turns the packed values into typed arrays.

  • tojson() gained an argument mode (and the option xfun.tojson.mode), a master switch over every construct that is not strict JSON. With the default mode = "js", dates become new Date(...), Inf/-Inf become Infinity/-Infinity, and dict/pack-encoded vectors become self-contained JavaScript expressions (an unpack(...) call, wrapped in an IIFE that defines unpack()). With mode = "json", the whole output is standard JSON that JSON.parse() accepts: dates become plain quoted strings, Inf/-Inf become null (as JSON.stringify() does), and dict/pack-encoded vectors become tagged objects that json_reviver expands back. This replaces the mode field previously read from the pack argument.

  • browser_print() and browser_dom() now run the headless browser with its temporary directory pointed at a private subdirectory that is deleted afterward, so the browser's scratch files (e.g. com.google.Chrome.*) no longer accumulate in the session's temp directory (which also tripped R CMD check's detritus NOTE for packages using these functions).

  • submit_cran() (and the automatic tarball build behind it) now runs optional build hooks: scripts named tools/build-before.* and tools/build-after.* in the package are run before and after R CMD build (.R via Rscript, .sh via sh). A build-before script can generate files that ship in the tarball but are not kept in the source tree (e.g. download or minify assets), and the build-after script (run even if the build fails) can restore the source tree.