Browse thread
announcement - Col: from records to CSV and vice-versa
- Martin Jambon
[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Martin Jambon <martin_jambon@e...> |
| Subject: | announcement - Col: from records to CSV and vice-versa |
Col is a syntax library for the conversion between lists of records and
CSV files with header. CSV (Comma-Separated Values) is a text format
supported by spreadsheet programs. "records" are represented as OCaml
records, tuples or objects, all being available and interconvertible.
main URL: http://martin.jambon.free.fr/ocaml.html#col
development/discussion wiki: http://ocaml.pbwiki.com/Col
For a demonstration of what the syntax can do, see
http://martin.jambon.free.fr/col-doc.html
Here is a short example which defines a list of 2 records and saves them:
(* File test.ml *)
type col t = { x : float;
y : float;
title "The Title" : string = "no title" }
let data =
let x = 1. in
[ T.create ~x ~y:2. ();
T.create ~y:4. ~x ~title:"line2" () ]
let _ = T.save_csv "data.csv" data
(* end *)
$ ocamlfind ocamlopt -o testcol test.ml -syntax camlp4o -package col -linkpkg
$ ./testcol
$ cat data.csv
x,y,"The Title"
1.,2.,"no title"
1.,4.,line2
$
This package is not well-documented but I have been using it intensively
with openoffice.org and gnuplot, and it is stable. My largest record type
has 49 fields and is still growing!
Have fun!
--
Martin Jambon, PhD
http://martin.jambon.free.fr
Edit http://wikiomics.org, bioinformatics wiki