Skip to content

gather() should possibly generate warnings or errors when key and value columns overlap with column in input #496

@JohnMount

Description

@JohnMount

It seems like some of the examples below should generate warnings or errors.

df <- data.frame(
  x = 1:3, 
  y = 4:6, 
  choice = c("x", "y", "x"), 
  stringsAsFactors = FALSE)
  
tidyr::gather(df, "k", "v")


    ##        k v
    ## 1      x 1
    ## 2      x 2
    ## 3      x 3
    ## 4      y 4
    ## 5      y 5
    ## 6      y 6
    ## 7 choice x
    ## 8 choice y
    ## 9 choice x


tidyr::gather(df, "k", "x")


    ##        k x
    ## 1      y 4
    ## 2      y 5
    ## 3      y 6
    ## 4 choice x
    ## 5 choice y
    ## 6 choice x


tidyr::gather(df, "x", "v")


    ##        x v
    ## 1      y 4
    ## 2      y 5
    ## 3      y 6
    ## 4 choice x
    ## 5 choice y
    ## 6 choice x


tidyr::gather(df, "x", "y")


    ##        x y
    ## 1 choice x
    ## 2 choice y
    ## 3 choice x


tidyr::gather(df, "x", "x")


    ##        x x
    ## 1      y 4
    ## 2      y 5
    ## 3      y 6
    ## 4 choice x
    ## 5 choice y
    ## 6 choice x

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

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions