TimTeaFan / dplyover

Create columns by applying functions to vectors and/or columns in 'dplyr'.
https://timteafan.github.io/dplyover/
Other
61 stars 0 forks source link

`across2x()` `.comb = "minimal"` argument not working correctly #21

Open TimTeaFan opened 1 year ago

TimTeaFan commented 1 year ago

.comb = "minimal" is not working if we use NULL inside .fns.

library(tidyverse)
library(dplyover)

df <- tibble(V1 = sample(c(0,1), 25, replace=TRUE, prob=c(0.6, 0.4)),
             V2 = sample(c(0,1), 25, replace=TRUE, prob=c(0.6, 0.4)),
             V3 = sample(c(0,1), 25, replace=TRUE, prob=c(0.8, 0.2)),
             V4 = sample(c(0,1), 25, replace=TRUE, prob=c(0.7, 0.3)),
             V5 = sample(c(0,1), 25, replace=TRUE, prob=c(0.8, 0.2)),
             V6 = sample(c(0,1), 25, replace=TRUE, prob=c(0.8, 0.2)),
             V7 = sample(c(0,1), 25, replace=TRUE, prob=c(0.8, 0.2)))

df %>% 
  mutate(across2x(everything(),
                  everything(),
                  ~ {
                    check <- .x * .y
                    if (!any(check)) {
                      NULL }
                    else {
                      ifelse(check, 1, 0 )
                      }
                  },
                  .comb = "minimal"
                  )
  )
#> Error in `mutate_cols()`:
#> ! Problem with `mutate()` input `..1`.
#> i `..1 = across2x(...)`.
#> x Attribut 'names' [49] muss dieselbe Länge haben wie der Vektor [42]
#> Caused by error in `names(out) <- names`:
#> ! Attribut 'names' [49] muss dieselbe Länge haben wie der Vektor [42]

Created on 2023-01-24 by the reprex package (v2.0.1)