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

across does not handle lists of functions stored as an external variable #473

Open
Xitian9 opened this issue May 19, 2024 · 0 comments
Open

Comments

@Xitian9
Copy link

Xitian9 commented May 19, 2024

across is normally able to accept a list of functions which will all be applied to the selected columns. This works in dtplyr if the list is supplied directly in across, but not if it's stored as a variable and substituted in.

library(dplyr)

df <- data.table::data.table(
  x = seq(1, 10)
)

# Store list of summary functions as a variable
summaries <- list(
  "Mean" = mean,
  "SD" = sd
)

# Throws an error that summaries is not a function
df |>
  dtplyr::lazy_dt() |>
  summarise(across("x", summaries)) |>
  data.table::as.data.table()

# Works fine if not a lazy data table
df |>
  summarise(across("x", summaries)) |>
  data.table::as.data.table()

# Also works fine if the list is written within the call
df |>
  dtplyr::lazy_dt() |>
  summarise(across("x", list("Mean" = mean, "SD" = sd))) |>
  data.table::as.data.table()
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

No branches or pull requests

1 participant