You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
toon is a dependency-free R package that provides functions to serialize native R objects (lists, data frames, vectors) into the Token-Oriented Object Notation (TOON) format.
TOON is specifically designed to significantly reduce token usage when passing structured data to Large Language Models (LLMs). It offers a substantial token-efficiency advantage over traditional formats like JSON, particularly for tabular or highly uniform data.
Installation
Install the stable or development versions:
# CRAN version
install.packages("toon")
# Dev version## If you don't have 'remotes' installed, run: install.packages('remotes')remotes::install_github("laresbernardo/toon")
Usage Example
The primary function is as_toon(), which takes an R object and returns a toon class string.
Complex List Serialization
Let's define a complex R list containing vectors, a data frame, and nested lists (objects and arrays):
While the complex example shows toon's restructuring capabilities, its most powerful use case is dramatically reducing the size of datasets.
x<-iris# A simple 150 rows and 5 columns dataset# Compare the TOON string size to a standard JSON string
nchar(as_toon(x)) / nchar(jsonlite::toJSON(x))
# Result: ~0.28 (Same info, roughly 28% the size)
Read More about TOON
The toon package is based on and inspired by the official format specification. You can read more about the Token-Oriented Object Notation here: