Scautable now supports flexible header handling using the new HeaderOptions enum. This allows fine-grained control over how headers are extracted or constructed from CSV input.

Currently only available for the fromString method

import io.github.quafadas.table.*

Available Options

HeaderOptions.AutoGenerated

Creates headers automatically:

col_0, col_1, col_2, ...

Useful when your CSV has no headers or you're working with raw tabular data.

HeaderOptions.Manual(headers: String*)

Provides explicit header names:

val manual = CSV.fromString("1,2,3", HeaderOptions.Manual("a", "b", "c"))
manual.headers // List("a", "b", "c")

HeaderOptions.FromRows(merge: Int, dropFirst: Int = 0)

Combines multiple rows from the start of the file into multi-line headers. Also allows skipping initial metadata rows.

Behavior:

  • Skips the first dropFirst rows (commonly used to ignore comments or metadata).
  • Then reads the next merge rows.
  • These rows are transposed so columns align.
  • Each column is joined using " " to produce a final header.

Example:

val csvContent = "Name,Age\nFirst,Years\nAlice,30\nBob,24"

val multiLine = CSV.fromString(csvContent, HeaderOptions.FromRows(merge = 2))
multiLine.headers

This is useful when your data source encodes hierarchical or descriptive headers across multiple lines.

HeaderOptions.Default Behavior

The default configuration is:

HeaderOptions.FromRows(merge = 1, dropFirst = 0)

This corresponds to the traditional single-row header handling.