Skip to content

summarize(across(where)) fails when using a predicate and acts unexpectedly with predicate negation #271

@roni-fultheim

Description

@roni-fultheim

I have been trying to summarize across numeric columns using dtplyr and summarise(across(where(is.numeric))) and got the error can't rename variables in this context. It took me quite a while to figure out the reason for the error is the usage of a predicate within summarize is not possible with dtplyr.
Is there any substitute for using is.numeric besides for naming all columns?
Thank you

The following code 1) shows error when using predicate, 2) show how the negation does not fail and applies given function to all variables (numeric and non-numeric)

library(ggplot2)
library(data.table)
library(dtplyr)
library(dplyr, warn.conflicts = FALSE)

# fails
diamonds %>% lazy_dt() %>% group_by(color) %>% summarise(across(!where(is.numeric), first))

# applies function to all variables
diamonds %>% lazy_dt() %>% group_by(color) %>% summarise(across(!where(is.numeric), first))

# unlike the equivalent statement using a data frame which only returns the relevant variables
diamonds %>% group_by(color) %>% summarise(across(!where(is.numeric), first))

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions