knitr::opts_chunk$set(echo = TRUE)
Package connects R session with KDB process. It can be used to
date$(); sy:
symbol$(); " # define a table
"t:("DS"; enlist ",") 0: `:file.csv" # load csvNote: operation result is not returned back to R session.
"select from t" "10#select from t"
// creates a java connection manager create() ex: manager = create()
// connects to Q session connect(manager (javaref),host(string),port (string/int)) ex: handle = connect(manager,"localhost", 5000L)
// execute remote statement exec( handle, "statement") ex: manager.exec(handle,"x: 1 2 3")
// retrieve as data frame select( handle(int), query(string)) ex: df=select(manager,h1,"3#select from t")
you can also access a low-level Q driver inside conmgr.
// close Q session connect(manager(javaref),handle(int))
KDB process live and listening on a port. Ex: >q -p 5000
Due to performance, package will implement the following conversions: date(d) - returned to R as numeric time(t) - returned to R as numeric. datetime(z) - returned to R as string "2016.12.24 21:16:38.067 EST"
Implementation may change.
Package uses Java library to connect to and translate KDB types.
Example: KDB and R are started locally. table: 1M rows x 10 columns, 62455442 bytes. 1. Java library retrieves 1M records in 0.9 seconds. 2. R package retrieves 1M rows and converts to dataframe in ~10 seconds.
//create table
t1:([] date:date$(); time:
time$(); sy:symbol$(); vboolean:
boolean$(); charvalue:char$(); str:(); px:
float$(); volume:int$(); long:
long$(); tm:`datetime$() )
//fill with dummy data
t1 insert(2016.12.1; "T"$"07:00:00.000";
FOO; 0b; "a"; "xyz"; 1.345f; 100; 1099511627776j; .z.Z )
`t1 insert(til 1000; .... )
# open session to one or more Q instances manager = initmgr() h1 = connect(manager,"localhost", 5000L) h2 = connect(manager,"host", "port") # execute remotely exec(manager,h1,"x: 1 2 3") exec(manager,h1,".Q.w[]") # retrieve as R data frame df1=select(manager,h1,"10#select from t1") head(df1) # retrieve as R data frame, Q memory stats df2=select(manager,h1,"select from ([] k:key .Q.w[]; v:value .Q.w[])") head(df2) # close Q connection. close(manager,h1)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.