All Projects → KxSystems → rkdb

KxSystems / rkdb

Licence: Apache-2.0 license
R client for kdb+

Programming Languages

c
50402 projects - #5 most used programming language
r
7636 projects

Projects that are alternatives of or similar to rkdb

javakdb
Using Java with kdb+
Stars: ✭ 41 (+10.81%)
Mutual labels:  interface, kdb, q
kafka
kdb+ to Apache Kafka adapter, for pub/sub
Stars: ✭ 38 (+2.7%)
Mutual labels:  interface, kdb, q
docs
Source for documentation site
Stars: ✭ 73 (+97.3%)
Mutual labels:  kdb, q
ml
Machine-learning toolkit
Stars: ✭ 48 (+29.73%)
Mutual labels:  kdb, q
q-mode
Emacs mode for editing q scripts and communicating with inferior q/qcon buffers
Stars: ✭ 21 (-43.24%)
Mutual labels:  kdb, q
ml.q
Machine Learning for kdb+/q
Stars: ✭ 25 (-32.43%)
Mutual labels:  kdb, q
jupyterq
Jupyter kernel for kdb+
Stars: ✭ 87 (+135.14%)
Mutual labels:  kdb, q
kdb-tick
Latest source files for kdb+tick
Stars: ✭ 73 (+97.3%)
Mutual labels:  kdb, q
q4q
Source Code for "Q for Quants"
Stars: ✭ 22 (-40.54%)
Mutual labels:  kdb, q
docs-v1
Source of code.kx.com/q
Stars: ✭ 33 (-10.81%)
Mutual labels:  kdb, q
vscode-q
vscode kdb+/q extension
Stars: ✭ 34 (-8.11%)
Mutual labels:  kdb, q
kdb nim
Nim Kdb type-safe bindings
Stars: ✭ 13 (-64.86%)
Mutual labels:  kdb, q
automl
Automated Machine Learning Framework for kdb+
Stars: ✭ 22 (-40.54%)
Mutual labels:  kdb, q
Django Colorfield
color field for django models with a nice color-picker in the admin. 🎨
Stars: ✭ 238 (+543.24%)
Mutual labels:  interface
ui bibz
Ui Framework based on Bootstrap and Ruby on Rails
Stars: ✭ 13 (-64.86%)
Mutual labels:  interface
Elvui
ElvUI for World of Warcraft - Wrath of the Lich King (3.3.5a)
Stars: ✭ 229 (+518.92%)
Mutual labels:  interface
Pfui
A User Interface Replacement for World of Warcraft: Vanilla & TBC
Stars: ✭ 226 (+510.81%)
Mutual labels:  interface
youyou
Edit and create FHIR profiles with a shiny interface ✨
Stars: ✭ 13 (-64.86%)
Mutual labels:  interface
Lxc Web Panel
LXC Web Panel improved for lxc 1.0+
Stars: ✭ 223 (+502.7%)
Mutual labels:  interface
Dbi
A database interface (DBI) definition for communication between R and RDBMSs
Stars: ✭ 215 (+481.08%)
Mutual labels:  interface

R client for kdb+

GitHub release (latest by date) Travis (.org) branch AppVeyor branch

Execute kdb+ queries from R for advanced high-performance analytics.

See Interfacing with R on code.kx.com.

Installation

# remove old package
if('qserver' %in% rownames(installed.packages())) remove.packages('qserver')
# install devtools
if(! 'devtools' %in% rownames(installed.packages())) install.packages('devtools')
library(devtools)
# install rkdb
devtools::install_github('kxsystems/rkdb', quiet=TRUE,INSTALL_opts=c("--no-multiarch"))
# to install rkdb of particular release
# devtools::install_github('kxsystems/[email protected]', quiet=TRUE)
library(rkdb)

First steps

Set up a connection

Start a kdb+ process to test the installation.

q -p 5000

Open a connection to it.

h <- open_connection('localhost',5000)

Hello kdb+

You can evaluate any kdb+ expression and its result will come back to R:

execute(h, '1+1')

    ## [1] 2

Assigning a variable in the q workspace also works:

execute(h, 'x:1+1') #assign x to 2

    ## NULL

execute(h, 'x') # get back the value

    ## [1] 2

Getting data from kdb+ to R

Kdb+ uses some basic types that might not have a direct equivalent in R. Note also that this is not a bijective operation. The conversions (from kdb to R) are:

kdb/q r
boolean logical
byte raw
short integer
int integer
long integer64
real numeric
float numeric
char character
symbol character
timestamp nanotime
month integer
date Date
datetime POSIXct
timespan integer64
minute difftime
second difftime
time integer
enumeration character
table data.frame
keyed table data.frame
dictionary (mixed types) named list
dictionary (same types) named vector
function character
list (same types) vector
list (same ‘complex’ types) list
list (different types) list

Computing on kdb+

Rkdb provides a convenient way to retrieve computation done on the kdb+ side so you can have the best of both worlds:

kdb <- '
t: ([] x:1000#`a`b`c;y:1000#1f*til 10;z:1000#1f*til 4);
select sum y, dev z by x from t
'

execute(h, kdb)

    ##   x    y        z
    ## 1 a 1503 1.120709
    ## 2 b 1497 1.116689
    ## 3 c 1500 1.116689

One can for instance use R graphical capabilities:

kdb <- '
t: ([] x:1000#`a`b`c;y:1000#1f*til 10;z:1000#1f*til 4);
select y,z from t where x=`a
'

DF <- execute(h, kdb)
plot(DF$y, DF$z, main='scatter plot', xlab='y values', ylab='z values')

Getting data from R to kdb+

Evaluating kdb+ expressions using R objects

You can call kdb+ functions with R objects as arguments. They will be passed and converted to native kdb+ data types, and the kdb+ expression will be evaluated:

execute(h, "raze", list(c(1,2,3), c(4,5,6)))

    ## [1] 1 2 3 4 5 6

execute(h, "+", 2, 5)

    ## [1] 7

execute(h,'{`tmp set x}',data.frame(a=c(1,2,3),b=c("a","b","b")))

    ## [1] "tmp"

For example, here is how you can use the left-join function on two data frames:

DF1 <- data.frame(x=c('x','x','y','y'), y=1:4)
DF2 <- data.frame(x=c('x','y','z'), z=seq(10,30,10))
execute(h, "{[x;y] x lj `x xkey y}", DF1, DF2)

    ##   x y  z
    ## 1 x 1 10
    ## 2 x 2 10
    ## 3 y 3 20
    ## 4 y 4 20
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].