使用mutate()中的自定义函数与dplyr& monetDB

时间:2016-02-23 16:05:50

标签: r monetdb monetdblite

我刚刚开始发现使用R&的所有优点monetDB / monetDBLite包裹 - 很棒的东西!
我很好奇,如果可以在dplyr的{​​{1}}中使用自定义函数,即

mutate()

导致以下错误:

# Connect to monetDBLite
db <- src_monetdb(embedded = db.dir)
data <- tbl(db, "my.table")

# Try to make a new column using custom defined function  
data %>% group_by(colX) %>% mutate(NewCol = customFunc())  

似乎SQL解析器在查找自定义函数时遇到问题。我是否监督某事(在Error in .local(conn, statement, ...) : Unable to execute statement 'SELECT colA colB colC...'. Server says 'ParseException:SQLparser:SELECT: no such operator 'customFunc''. 函数定义中声明R代码等)?是否可以使用SQL包这样的自定义函数?

1 个答案:

答案 0 :(得分:0)

由于@Hannes在评论中回答了我的问题 - 我在这里添加了一些其他的东西:

  • 可以将基本的dplyr动词(selectfiltergroup_by&amp; mutate)与其他一些动词一起使用“R功能。在“SQL转换”部分的dplyr databases vignette下,有一个受支持的函数列表,以及更多相关内容。所以,使用上面我的问题中的例子 - 人们可以这样做:
    data %>% group_by(col_x) %>% mutate(new_col = log10(some_old_col))

  • MonetDBLite不支持UDF(例如我的问题 - 如果可以在mutate调用中使用我的UDF)...

  • ...但是“full”MonetDB确实支持将已定义的函数发送到db进行计算。在他们的homepage

  • 上都有很好的解释