(kdb + / q):将`R`数据类型转换为`q`

时间:2015-05-13 12:15:36

标签: r kdb q-lang

是否有人将q类型的完整转换为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") 原子类型?

类似的东西:

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"

允许写

as.qtype <- function(x) {
  if(class(x) %in% "logical") return(as.qboolean(x))
  if(class(x) %in% "numeric")
  ....}

甚至更通用的自动检测:

{{1}}

1 个答案:

答案 0 :(得分:0)

对于那些现在发现此问题的人来说...现在有许多R接口可用,包括https://github.com/KxSystems/rkdb,它具有kdb +类型的映射。文档位于自述文件中,位于https://code.kx.com/q/interfaces/with-r/#calling-q-from-r