MCPcopy Create free account
hub / github.com/cogentcore/core / WriteCSV

Method WriteCSV

tensor/table/io.go:396–417  ·  view source on GitHub ↗

WriteCSV WriteCSV writes a table to a comma-separated-values (CSV) file (where comma = any delimiter, specified in the delim arg). If headers = true then generate column headers that capture the type and tensor cell geometry of the columns, enabling full reloading of exactly the same table format a

(w io.Writer, delim Delims, headers bool)

Source from the content-addressed store, hash-verified

394// of exactly the same table format and data (recommended).
395// Otherwise, only the data is written.
396func (dt *Table) WriteCSV(w io.Writer, delim Delims, headers bool) error {
397 ncol := 0
398 var err error
399 if headers {
400 ncol, err = dt.WriteCSVHeaders(w, delim)
401 if err != nil {
402 log.Println(err)
403 return err
404 }
405 }
406 cw := csv.NewWriter(w)
407 cw.Comma = delim.Rune()
408 for ri := 0; ri < dt.Rows; ri++ {
409 err = dt.WriteCSVRowWriter(cw, ri, ncol)
410 if err != nil {
411 log.Println(err)
412 return err
413 }
414 }
415 cw.Flush()
416 return nil
417}
418
419// WriteCSV writes only rows in table idx view to a comma-separated-values (CSV) file
420// (where comma = any delimiter, specified in the delim arg).

Callers 2

SaveCSVMethod · 0.95
TestReadTableDatFunction · 0.95

Implementers 1

_cogentcore_org_core_plot_plots_Tableyaegicore/symbols/cogentcore_org-core-

Calls 5

WriteCSVHeadersMethod · 0.95
WriteCSVRowWriterMethod · 0.95
PrintlnMethod · 0.80
RuneMethod · 0.45
FlushMethod · 0.45

Tested by 1

TestReadTableDatFunction · 0.76