duckplyr icon indicating copy to clipboard operation
duckplyr copied to clipboard

Adding function translations for the session

Open brichards920 opened this issue 1 year ago • 4 comments

Using dplyr and dbplyr, it's possible to work around missing function translations by calling duckdb functions directly, or by writing macros that can do the translation.

Here's how I might quickly do something like that.

require(dplyr)
require(duckdb)

con <- dbConnect(duckdb())

dbSendStatement(con, 'create or replace macro TIMESTWO (x) as x::NUMERIC*2.0;')

out <- copy_to(con, iris, overwrite = T) %>%
  mutate(y = TIMESTWO(Sepal.Length)) %>%
  collect()

I run into fallback situations pretty quickly with duckplyr, and it would be nice to be able to write macros or adjust my code to work around them. If possible, could you please share an example of how I might do something like the above in duckplyr for my R session? I've been attempting to do this with relexpr_set_alias and to_duckdb_expr, but I haven't been making much progress.

brichards920 avatar May 06 '24 15:05 brichards920

Thanks, interesting idea.

The translations currently aren't very well organized (a lot happens in R/relational.R). Let me think about how to open this for extension.

krlmlr avatar May 07 '24 03:05 krlmlr

Until then, would you like to share examples of fallback situations that would help you most (perhaps one issue per example)?

krlmlr avatar May 07 '24 03:05 krlmlr

We now at least have a list of functions that are translated: https://github.com/duckdblabs/duckplyr/pull/179/files#diff-a202cfba76540d6822868ac7755edd4945b6344057d78e0092f4836e33c0d4eaR11 .

krlmlr avatar Jun 30 '24 16:06 krlmlr

Because we will never be able to translate everything, a way to provide custom translations can help bridge the gap in some cases.

For now, clone the repository and follow the contributing guide.

krlmlr avatar Jul 10 '24 20:07 krlmlr