cynkra / constructive

Display Idiomatic Code to Construct Most R Objects
https://cynkra.github.io/constructive
Other
132 stars 6 forks source link

duckplyr error with constructive 1.0.0, works with constructive 0.3.0 #449

Closed krlmlr closed 5 months ago

krlmlr commented 5 months ago

1.0.0

data.frame(a = 1:3) |>
  duckplyr::as_duckplyr_df() |>
  dplyr::mutate(pct = 100 * a / sum(a))
#> materializing:
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> Projection [a as a, ___divide(*(100.0, a), sum(a) OVER ()) as pct]
#>   r_dataframe_scan(0x10ea279e0)
#> 
#> ---------------------
#> -- Result Columns  --
#> ---------------------
#> - a (INTEGER)
#> - pct (DOUBLE)
#> 
#>   a      pct
#> 1 1 16.66667
#> 2 2 33.33333
#> 3 3 50.00000

duckplyr:::meta_replay()
#> Error in `FUN()`:
#> ! `call` must only be made of symbols and syntactic literals
#> Caused by error in `if (!x %in% names(precedences)) ...`:
#> ! the condition has length > 1

Created on 2024-07-03 with reprex v2.1.0

0.3.0

data.frame(a = 1:3) |>
  duckplyr::as_duckplyr_df() |>
  dplyr::mutate(pct = 100 * a / sum(a))
#> materializing:
#> ---------------------
#> --- Relation Tree ---
#> ---------------------
#> Projection [a as a, ___divide(*(100.0, a), sum(a) OVER ()) as pct]
#>   r_dataframe_scan(0x10ba259e0)
#> 
#> ---------------------
#> -- Result Columns  --
#> ---------------------
#> - a (INTEGER)
#> - pct (DOUBLE)
#> 
#>   a      pct
#> 1 1 16.66667
#> 2 2 33.33333
#> 3 3 50.00000

duckplyr:::meta_replay()
#> duckdb <- asNamespace("duckdb")
#> drv <- duckdb::duckdb()
#> con <- DBI::dbConnect(drv)
#> experimental <- FALSE
#> invisible(
#>   DBI::dbExecute(
#>     con,
#>     r"[CREATE MACRO "___divide"(x, y) AS CASE WHEN y = 0 THEN CASE WHEN x = 0 THEN CAST('NaN' AS double) WHEN x > 0 THEN CAST('+Infinity' AS double) ELSE CAST('-Infinity' AS double) END ELSE CAST(x AS double) / y END]"
#>   )
#> )
#> df1 <- data.frame(a = 1:3)
#> 
#> rel1 <- duckdb$rel_from_df(con, df1, experimental = experimental)
#> rel2 <- duckdb$rel_project(
#>   rel1,
#>   list(
#>     {
#>       tmp_expr <- duckdb$expr_reference("a")
#>       duckdb$expr_set_alias(tmp_expr, "a")
#>       tmp_expr
#>     },
#>     {
#>       tmp_expr <- duckdb$expr_function(
#>         "___divide",
#>         list(
#>           duckdb$expr_function(
#>             "*",
#>             list(
#>               if ("experimental" %in% names(formals(duckdb$expr_constant))) {
#>                 duckdb$expr_constant(100, experimental = experimental)
#>               } else {
#>                 duckdb$expr_constant(100)
#>               },
#>               duckdb$expr_reference("a")
#>             )
#>           ),
#>           duckdb$expr_window(duckdb$expr_function("sum", list(duckdb$expr_reference("a"))), list(), list(), offset_expr = NULL, default_expr = NULL)
#>         )
#>       )
#>       duckdb$expr_set_alias(tmp_expr, "pct")
#>       tmp_expr
#>     }
#>   )
#> )
#> rel2
#> duckdb$rel_to_altrep(rel2)

Created on 2024-07-03 with reprex v2.1.0

moodymudskipper commented 5 months ago

oh no, sorry about that :( I don't find the duckplyr:::meta_replay() (3 colons) function in neither the CRAN or dev version, is it on a branch ?

moodymudskipper commented 5 months ago

I think something just went wrong with the installation because I see it when I clone it but I get this after installing from GitHub with devtools::install_github()

packageVersion("duckplyr")
#> [1] '0.4.0.9002'
duckplyr:::meta_replay
#> Error in eval(expr, envir, enclos): object 'meta_replay' not found

FWIW pak::pak() was freezing so I couldn't use it.

krlmlr commented 5 months ago

Oh yeah, you need to clone and then R CMD INSTALL ., the "meta" code is rbuildignore-d .