hHw 通过 R 将系统功能传递给 MonetDB?

hHw to pass a system function to MonetDB through R?

使用 MonetDB.R,我想 运行 这个命令,但我不想打开 mclient。有通用的方法吗?

create function div_noerror(l double, r double) returns double

来自 MonetDB.R 的作者 Hannes --

您可以直接在您的数据库中创建它。如果它已经存在,这将失败,但您可以捕获该错误。所以

dbSendQuery(con, "create function div_noerror(l double, r double) returns double external name calc.div_noerror”) should work.

这里有一个稍长的用法示例:

# example of division
dbGetQuery( con , "SELECT 1 / 2 AS a" )

# example of division by zero, which causes an error
dbGetQuery( con , "SELECT 1 / 0 AS a" )

# load the `div_noerror` function through a system call
dbSendQuery( con , "CREATE FUNCTION div_noerror(l DOUBLE, r DOUBLE) RETURNS DOUBLE EXTERNAL NAME calc.div_noerror" ) 

# use the div_noerror function instead of the `/` operator
dbGetQuery( con , "SELECT div_noerror( 1 , 2 ) AS a" )

# division by zero now returns a missing instead of crashing the entire query
dbGetQuery( con , "SELECT div_noerror( 1 , 0 ) AS a" )