Skip to content

load, rload

Load binary data from a file or directory

load

Load binary data from a file

load x     load[x]

Where x is

  • a symbol atom or vector matching the names of datafiles (with no extension) in the current directory, reads the datafiles and assigns the values to global variables of the same names, which it returns
  • a filesymbol atom or vector for datafiles (with no extension), reads the datafiles and assigns the values to global variables of the same names, which it returns
  • a filesymbol for a directory, creates a global dictionary of the same name and within that dictionary recurses on any datafiles the directory contains

Binary data only

load signals an error if the file is not a KDB-X data file. It does not read the text formats that save can write; for those, use File Text.

q)t:([]x: 1 2 3; y: 10 20 30)
q)save`t             / save to a binary file (same as `:t set t)
`:t
q)delete t from `.   / delete t
`.
q)t                  / not found
't
  [0]  t                  / not found
       ^

q)load`t             / load from a binary file (same as t:get `:t)
`t
q)t
x y
----
1 10
2 20
3 30

Load a directory of datafiles into a dictionary:

q)s:([s:`s1`s2]name:`smith`jones)
q)p:([p:`p1`p2]color:`red`green)
q)`:cb/p set p
`:cb/p
q)`:cb/s set s
`:cb/s
q)load `cb
`cb
q)key cb
`s#`p`s
q)cb `s
s | name
--| -----
s1| smith
s2| jones

Operating systems may create hidden files, such as .DS_Store, that block load.

rload

Load a splayed table from a directory

rload x     rload[x]

Where x is the table name as a symbol, rload reads the table from the directory of the same name. rload is the converse of rsave.

q)sp:([]qty:300 200 400;px:1 2 3f)
q)rsave `sp           / save splayed table
`:sp/
q)delete sp from `.
`.
q)rload `sp           / load splayed table
`sp
q)sp
qty px
------
300 1
200 2
400 3

Use get for more flexibility

get is the usual, more general way to do this: it lets you give the table a different name from its source directory.

get returns a splayed table that refers to the directory, rather than a copy of the table in memory, so it doesn't match the result of rload with ~. Its rows do:

q)sp~get `:sp/
0b
q)sp~select from get `:sp/
1b

save, rsave, .Q.dsftg (load process save), .Q.fps (pipe streaming), .Q.fs (file streaming), .Q.fsn (file streaming with chunks), .Q.v (get splayed table)

File system

Q for Mortals §11.2 Save and Load on Tables