Skip to content

if_any inside mutate, unexpected return on single columns #7746

@mp8

Description

@mp8

I am not sure if this will be use case for any, but trying to use if_any directly inside mutate changes behavior unexpectedly when only single column is in the .cols with nothing specified for .fns. Apologies if this was already documented:

library(dplyr)

# Sample data
zdata <- tibble(
    id = 1:5,
    col_a = c(10, 25, 5, 30, 15),
    col_b = c(20, 12, 8, 40, 22),
    col_c = c(5, 18, 10, 15, 7)
)

#Trying to use if_any directly inside mutate, expected logical output
#Case1
zdata %>% mutate(any_big = if_any(c(col_a,col_b,col_c), ~ .x>10))  #Returns logical

#Case2
zdata %>% mutate(any_big = if_any(c(col_a,col_b,col_c)))                #Returns logical

#Case3
zdata %>% mutate(any_big = if_any(c(col_a), ~ .x>10))                   #Returns logical

#Case4
zdata %>% mutate(any_big = if_any(c(col_a)))                       #Does not return logical output, returns column as it is..

# A tibble: 5 × 5
     id col_a col_b col_c any_big
  <int> <dbl> <dbl> <dbl>   <dbl>
1     1    10    20     5      10
2     2    25    12    18      25
3     3     5     8    10       5
4     4    30    40    15      30
5     5    15    22     7      15


#Adding sessionInfo:

sessionInfo()
#> R version 4.5.1 (2025-06-13 ucrt)
#> Platform: x86_64-w64-mingw32/x64
#> Running under: Windows 10 x64 (build 19045)
#> 
#> Matrix products: default
#>   LAPACK version 3.12.1
#> 
#> locale:
#> [1] LC_COLLATE=English_United States.utf8 
#> [2] LC_CTYPE=English_United States.utf8   
#> [3] LC_MONETARY=English_United States.utf8
#> [4] LC_NUMERIC=C                          
#> [5] LC_TIME=English_United States.utf8    
#> 
#> time zone: America/Los_Angeles
#> tzcode source: internal
#> 
#> attached base packages:
#> [1] stats     graphics  grDevices utils     datasets  methods   base     
#> 
#> loaded via a namespace (and not attached):
#>  [1] digest_0.6.37     fastmap_1.2.0     xfun_0.53         glue_1.8.0       
#>  [5] knitr_1.50        htmltools_0.5.8.1 rmarkdown_2.30    lifecycle_1.0.4  
#>  [9] cli_3.6.5         reprex_2.1.1      withr_3.0.2       compiler_4.5.1   
#> [13] rstudioapi_0.17.1 tools_4.5.1       evaluate_1.0.5    yaml_2.3.10      
#> [17] rlang_1.1.6       fs_1.6.6

Metadata

Metadata

Assignees

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