Skip to content

pivot_wider() should drop values_from with zero row data frames #1249

@DavisVaughan

Description

@DavisVaughan
library(tidyr)

pivot_wider(fish_encounters[1,], names_from = station, values_from = seen)
#> # A tibble: 1 × 2
#>   fish  Release
#>   <fct>   <int>
#> 1 4842        1

# Doesn't drop `seen`, but dropped `station`
pivot_wider(fish_encounters[0,], names_from = station, values_from = seen)
#> # A tibble: 0 × 2
#> # … with 2 variables: fish <fct>, seen <int>

# Works if you explicitly state the `id_cols`
pivot_wider(fish_encounters[0,], id_cols = fish, names_from = station, values_from = seen)
#> # A tibble: 0 × 1
#> # … with 1 variable: fish <fct>

I think I am expecting just an empty fish column

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugan unexpected problem or unintended behaviorpivoting ♻️pivot rectangular data to different "shapes"

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions