I am just beginning to discover all the advantages of using R
& monetDB
/monetDBLite
package - great stuff!
I was curious however if it's possible to use a custom defined function in dplyr
's mutate()
i.e.
# 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())
Results in the following error:
Error in .local(conn, statement, ...) :
Unable to execute statement 'SELECT colA colB colC...'.
Server says 'ParseException:SQLparser:SELECT: no such operator 'customFunc''.
It seems like the SQL parser has a problem finding the custom function. Am I overseeing something (declare R
code in a SQL
function definition etc.) ? Is it possible to use custom defined functions with the monetDBLite
package like this?
Since @Hannes answered my question in the comments - i'm adding it here with some other stuff i picked up:
one can use the basic
dplyr
verbs (select
,filter
,group_by
&mutate
) in conjunction with some other "basic"R
functions. There is a list of the supported functions, and more on this, in thedplyr
databases vignette under the section "SQL translation". So, using the example from my question above - one can do:data %>% group_by(col_x) %>% mutate(new_col = log10(some_old_col))
.MonetDBLite
does not support UDFs (e.g. my question here - if it's possible to use my UDF inside amutate
call) ...... however the "full"
MonetDB
does support used defined functions to be sent to the db for computation. It is all well explained on their homepage.