Learn R Programming

toon (version 0.0.1)

as_toon: Convert R Objects to TOON (Token-Oriented Object Notation)

Description

Converts a variety of R objects, including named lists (objects), unnamed lists, vectors (arrays), and data frames, into a character string formatted according to TOON (Token-Oriented Object Notation) specification.

Usage

as_toon(x, ...)

# S3 method for toon print(x, ...)

Value

A character vector of class toon, containing the fully formatted TOON string.

Arguments

x

The R object to be converted. Supported types include:

  • Named lists

  • Unnamed lists and atomic vectors

  • Data frames

  • Primitive types (numeric, character, logical, NULL)

...

Additional arguments passed to specific S3 methods (e.g., internal indentation parameters).

Details

TOON is designed as a highly human-readable, lightweight data serialization format that supports nested structures.

Examples

Run this code
# 1. Simple Object (Named List)
config_obj <- list(
  version = 1.0,
  is_active = TRUE,
  user_id = 99
)
as_toon(config_obj)

# 2. Expanded Array (Unnamed List)
items <- list(
  "apple",
  list(color = "red", weight = 150),
  "banana"
)
as_toon(items)

# 3. Data Frame
df <- data.frame(
  time = c(9.1, 15.4),
  action = c("login", "update"),
  success = c(TRUE, FALSE)
)
as_toon(df)

Run the code above in your browser using DataLab