Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expr_scrub() seems like it can bork some expressions entirely #268

Closed
DavisVaughan opened this issue Oct 2, 2024 · 1 comment · Fixed by #271
Closed

expr_scrub() seems like it can bork some expressions entirely #268

DavisVaughan opened this issue Oct 2, 2024 · 1 comment · Fixed by #271

Comments

@DavisVaughan
Copy link
Member

library(duckplyr)
Sys.setenv(DUCKPLYR_FALLBACK_COLLECT = 1)
df <- tibble(x = 1:5, y = 6:10)
df <- as_duckplyr_df(df)
mutate(df, across(x:y, \(arg) mean(arg, na.rm = TRUE)))
#> Error in `as_string()`:
#> ! Can't convert an internal string to a string.

Minimal reprex:

name_map <- c(
  "...1",
  "...2",
  "...3"
)
names(name_map) <- c("x", "y", "")

expr <- quote(
  across(x:y, function(arg) mean(arg, na.rm = TRUE))
)

# something here is the problem
duckplyr:::expr_scrub(expr, name_map)
#> Error in print.default(x): badly formed function expression

broken <- duckplyr:::expr_scrub(expr, name_map)
rlang::expr_deparse(broken)
#> Error in `as_string()`:
#> ! Can't convert an internal string to a string.
@toppyy
Copy link
Contributor

toppyy commented Oct 9, 2024

It seems to fail when scrubbing the function definition which results in a "badly formed function expression". More specifically, it cannot handle the parameters which are stored in a pairlist (this can be observed by switching the last call to paste0 in do_scrub to stop).

Made a PR in which changes the behaviour so that the function parameters and body are scrubbed separately.

A reprex of the results with the example above

name_map <- c(
  "...1",
  "...2",
  "...3"
)
names(name_map) <- c("x", "y", "z")
name_map
#>      x      y      z 
#> "...1" "...2" "...3"

expr <- quote(
  across(x:y, function(arg) mean(arg, na.rm = TRUE))
)

# something here is the problem
duckplyr:::expr_scrub(expr, name_map)
#> across(...1:...2, (function(arg) mean(...4, na.rm = TRUE))())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants