Easiest thing:
Connect from the web.

Set up a console

q sp.q -p 5001

http://localhost:5001
http://localhost:5001/?select from s where name=`smith

export to excel:

http://localhost:5001/foo.csv?select from s where name=`smith



====
You might have to load a good version of gcc (4.7 or later works).
To load a new version of gcc on Macs, see the file plumbing in this directory
Everything else will work quite well even if you have an older version of
R or of an operating system.

Once you have done that
q -p 5000

R
and within the R interpreter source("qtest.R")

A little dissection: qtest.R calls qserver.R which sets up
the connections.
qserver.R has the port 5000 in there explicitly.
You can change that if you want.

Let's look at qtest.R

First, load the connection part and open the connection.

source("qserver.R")
h=open_connection()

Next, cause the q process to load sp.q

execute (h,"\\l sp.q")

Now execute various q commands in the q process

s=execute(h,"select[5] from sp") -- selects 5 lines from sp
execute (h,"a:.z.d") -- makes variable a have the date
execute (h,"b:a+100 * til 5") -- makes variable b have lots of dates
execute (h,"c:.z.z") -- c has date time
execute (h,"d:c+1.23 * til 5") -- d has lots more datetimes

show(s) -- result of the query
show(execute(h,"b")) -- value of q variable b
show(execute(h,"d")) -- value of q variable d

# close_connection(h)
