save, rsave¶
Write global data to file or splayed to a directory
save¶
Write a global variable to file and optionally format data
save x save[x]
Where x is a symbol atom or vector of the form [path/to/]v[.ext] in which
vis the name of a global variablepath/to/is a file path (optional). If a file- exists, it is overwritten
- does not exist, it is created, with any required parent directories
.extis a file extension (optional) which effects the file content format. Options are:(none)for binary formatcsvfor comma-separated valuestxtfor plain text)xlsfor Excel spreadsheet formatxmlfor Extensible Markup Language (XML))jsonfor JavaScript Object Notation (JSON) Since v3.2 2014.07.31.
writes global variable/s v etc. to file and returns the filename/s.
.h (data serialization tools)
Examples¶
q)t:([]x:2 3 5; y:`ibm`amd`intel; z:"npn")
q)save `t / binary
`:t
q)read0 `:t
"\377\001b\000c\013\000\003\000\000\000x\000y\000z\000\000\..
"\000\003\000\000\000npn"
q)save `t.csv / CSV
`:t.csv
q)read0 `:t.csv
"x,y,z"
"2,ibm,n"
"3,amd,p"
"5,intel,n"
q)save `t.txt / text
`:t.txt
q)read0 `:t.txt / columns are tab separated
"x\ty\tz"
"2\tibm\tn"
"3\tamd\tp"
"5\tintel\tn"
q)save `t.xls / Excel
`:t.xls
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
`:t.xml
q)read0 `:t.xml / tab separated
"<R>"
"<r><x>2</x><y>ibm</y><z>n</z></r>"
"<r><x>3</x><y>amd</y><z>p</z></r>"
"<r><x>5</x><y>intel</y><z>n</z></r>"
"</R>"
q)save `$"/tmp/t" / file path
`:/tmp/t
q)a:til 6
q)b:.Q.a
q)save `a`b / multiple files
`:a`:b
Use set instead to save
- a variable to a file of a different name
- local data
rsave¶
Write a table splayed to a directory
rsave x rsave[x]
Where x is a table name as a symbol atom, saves the table, in binary format, splayed to a directory of the same name.
The table must be fully enumerated and not keyed.
If the file
- exists, it is overwritten
- does not exist, it is created, with any required parent directories
Limits¶
The usual and more general way of doing this is to use set, which allows the target directory to be specified.
The following example uses the table sp created using the script sp.q
q)\l sp.q
q)rsave `sp / save splayed table
`:sp/
q)\ls sp
,"p"
"qty"
,"s"
q)`:sp/ set sp / equivalent to rsave `sp
`:sp/
set,
.h.tx,
.Q.dpft (save table),
.Q.Xf (create file)
File system
Q for Mortals
§11.2 Save and Load on Tables
Q for Mortals
§11.3 Splayed Tables