1

Has anyone written a complete conversion of R types to q atomic types?

Something like:

as.qsymbol <- function(x) UseMethod("as.qsymbol")
as.qboolean <- function(x) UseMethod("as.qboolean")

as.qsymbol.character <- function(x)
  structure(paste0('`$("',paste0(paste0(x,collapse = '";"'), '")')), class="qsymbol")

as.qboolean.logical <- function(x) 
  structure(ifelse(x==TRUE,"1b","0b"), class="qboolean")

Allowing to write

as.qboolean(c(TRUE, FALSE))
# [1] "1b" "0b"
# attr(,"class")
# [1] "qboolean"

as.qsymbol(c("foo", "bar baz"))
# [1] "`$(\"foo\";\"bar baz\")"
# attr(,"class")
# [1] "qsymbol"

Or even more generic autodetection:

as.qtype <- function(x) {
  if(class(x) %in% "logical") return(as.qboolean(x))
  if(class(x) %in% "numeric")
  ....}
Daniel Krizian
  • 4,586
  • 4
  • 38
  • 75

1 Answers1

0

For those finding this question now... There are a number of R interfaces now available, including https://github.com/KxSystems/rkdb, which has mappings for kdb+ types. Documentation is in the README, and at https://code.kx.com/q/interfaces/with-r/#calling-q-from-r

user2242865
  • 567
  • 5
  • 18