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
| Name | Description |
|---|---|
| cell | Returns a cell converted by a primitive type tag. |
| clear | Clears all in-memory CSV data. |
| column | Returns a CSV column as a vector-shaped array or matrix. |
| column_count | Returns the number of data columns. |
| column_index | Returns a named column's index, or -1 when absent. |
| column_name | Returns a column label. |
| column_names | Returns all column labels. |
| insert_column | Inserts and labels a CSV column from a vector-shaped array or matrix. |
| insert_row | Inserts and labels a CSV row from a vector-shaped sparse matrix. |
| path | Returns the resolved CSV path. |
| reload | Discards changes and reloads the CSV file. |
| remove_column | Removes a named column. |
| remove_row | Removes a named row. |
| row | Returns a named row converted by a primitive type tag. |
| row_count | Returns the number of data rows. |
| row_index | Returns a named row's index, or -1 when absent. |
| row_name | Returns a row label. |
| row_names | Returns all row labels. |
| save | Atomically writes changes to the current path. |
| save_as | Atomically writes changes to a new relative path. |
| set_cell | Sets a cell. |
| set_column | Replaces a named CSV column from a vector-shaped array or matrix. |
| set_column_name | Sets a column label. |
| set_row | Replaces a named CSV row from a vector-shaped array or matrix. |
| set_row_name | Sets a row label. |