Skip to main content

CSVFile

Base class: Object

Represents a CSV file held in memory.

CSV data is loaded on first access. Changes are written only by save() or save_as().

Example​

var csv = CSVFile("people", "w")
csv.set_column_name(0, "name").set_column("name", ["Ada", "Grace"]).save()
var names = CSVFile("people.csv", "r").column("name")

Constructors​

CSVFile(const string path) -> CSVFile​

Prepares a CSV file in append/update mode.

Parameters​

  • path: Relative file path.

CSVFile(const string path, const string mode) -> CSVFile​

Prepares a CSV file with an explicit mode.

Modes are "r", "r+", "w", "w-"/"x", and "a".

Parameters​

  • path: Relative file path.
  • mode: File mode.

CSVFile(const string path, const string mode, const Map options) -> CSVFile​

Prepares a CSV file with immutable parsing and writing options.

Parameters​

  • path: Relative file path.
  • mode: File mode.
  • options: CSV options map.

Members​

NameDescription
cellReturns a cell converted by a primitive type tag.
clearClears all in-memory CSV data.
columnReturns a CSV column as a vector-shaped array or matrix.
column_countReturns the number of data columns.
column_indexReturns a named column's index, or -1 when absent.
column_nameReturns a column label.
column_namesReturns all column labels.
insert_columnInserts and labels a CSV column from a vector-shaped array or matrix.
insert_rowInserts and labels a CSV row from a vector-shaped sparse matrix.
pathReturns the resolved CSV path.
reloadDiscards changes and reloads the CSV file.
remove_columnRemoves a named column.
remove_rowRemoves a named row.
rowReturns a named row converted by a primitive type tag.
row_countReturns the number of data rows.
row_indexReturns a named row's index, or -1 when absent.
row_nameReturns a row label.
row_namesReturns all row labels.
saveAtomically writes changes to the current path.
save_asAtomically writes changes to a new relative path.
set_cellSets a cell.
set_columnReplaces a named CSV column from a vector-shaped array or matrix.
set_column_nameSets a column label.
set_rowReplaces a named CSV row from a vector-shaped array or matrix.
set_row_nameSets a row label.