Skip to content

save, rsave

Save global data to file or splayed to a directory


Save global data to file

Syntax: save x, save[x]

Where x is a filename as a symbol, saves the global table to file and returns the filename. The file shortname (ignoring path and extension) must match the name of a global table. The format used depends on the file extension:

extension file format
(none) binary
csv comma-separated values
txt plain text
xls Excel spreadsheet
xml Extensible Markup Language (XML)
q)t:([]x:2 3 5;y:`ibm`amd`intel;z:"npn")
q)save `t            / binary
q)read0 `:t
q)save `t.csv        / CSV
q)read0 `:t.csv
q)save `t.txt        / text
q)read0 `:t.txt      / columns are tab separated
q)save `t.xls        / Excel
q)read0 `:t.xls
"<?xml version=\"1.0\"?><?mso-application progid=\"Excel.Sheet\"?>"
"<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" x...
q)save `t.xml       / XML
q)read0 `:t.xml    / tab separated

You can specify a path for the file:

q)save `$"/tmp/t"

Saving local data

To save local data you can do explicitly what save is doing implicitly.

q)`:t set t /save in binary format as a single file
q)/ save in binary format as a splayed table 
q)/ (1 file/column, symbols enumerated against the sym file in current dir)
q)`:t/ set .Q.en[`:.;t] 
q)`:t.csv 0:.h.tx[`csv;t] / save in csv format
q)`:t.txt 0:.h.tx[`txt;t] / save in txt format
q)`:t.xml 0:.h.tx[`xml;t] / save in xml format
q)`:t.xls 0:.h.tx[`xls;t] / save in xls format


Save a table splayed to a directory

Syntax: rsave x, rsave[x]

Where x is a table name as a symbol, saves the table, splayed to a directory of the same name. The table must be fully enumerated and not keyed.

The usual and more general way of doing this is to use set, which allows the target directory to be given.

q)\l sp.q
q)rsave `sp           / save splayed table
q)\ls sp
q)`:sp/ set sp        / equivalent to rsave `sp

.Q: .Q.dpft (save table), .Q.Xf (create file)
Basics: File system