Skip to content

using rowwise() on empty data.frames with list columns returns random booleans #7710

@Raoul-Kima

Description

@Raoul-Kima

When I use rowwise() on a zero-row tibble with a list column, and then compute something on that list column, the computing function gets fed randomly with either TRUE or FALSE, instead of always with with list().

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
tibble(a=list("test")) %>% 
    filter(a!="test") %>% 
    rowwise() %>%
    # group_by(a) %>%
    mutate(b=print(a))
#> [1] FALSE # <- this randomly is either TRUE or FALSE.
#> # A tibble: 0 × 2
#> # Rowwise: 
#> # ℹ 2 variables: a <list>, b <lgl>

Created on 2025-08-25 with reprex v2.1.1

When using group_by() instead, it works as expected:

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
tibble(a=list("test")) %>% 
    filter(a!="test") %>% 
    # rowwise() %>%
    group_by(a) %>%
    mutate(b=print(a))
#> list()
#> # A tibble: 0 × 2
#> # Groups:   a [0]
#> # ℹ 2 variables: a <list>, b <list>

Created on 2025-08-25 with reprex v2.1.1

This is with dplyr 1.1.4 and R version 4.5.1 (2025-06-13 ucrt)

Metadata

Metadata

Assignees

Labels

bugan unexpected problem or unintended behavior

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions