WriteCSV writes only rows in table idx view 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 tabl
(w io.Writer, delim Delims, headers bool)
| 423 | // of exactly the same table format and data (recommended). |
| 424 | // Otherwise, only the data is written. |
| 425 | func (ix *IndexView) WriteCSV(w io.Writer, delim Delims, headers bool) error { |
| 426 | ncol := 0 |
| 427 | var err error |
| 428 | if headers { |
| 429 | ncol, err = ix.Table.WriteCSVHeaders(w, delim) |
| 430 | if err != nil { |
| 431 | log.Println(err) |
| 432 | return err |
| 433 | } |
| 434 | } |
| 435 | cw := csv.NewWriter(w) |
| 436 | cw.Comma = delim.Rune() |
| 437 | nrow := ix.Len() |
| 438 | for ri := 0; ri < nrow; ri++ { |
| 439 | err = ix.Table.WriteCSVRowWriter(cw, ix.Indexes[ri], ncol) |
| 440 | if err != nil { |
| 441 | log.Println(err) |
| 442 | return err |
| 443 | } |
| 444 | } |
| 445 | cw.Flush() |
| 446 | return nil |
| 447 | } |
| 448 | |
| 449 | // WriteCSVHeaders writes headers to a comma-separated-values (CSV) file |
| 450 | // (where comma = any delimiter, specified in the delim arg). |
no test coverage detected